vuex映射值时出错Computed property "city" was assigned to but it has no setter
来源:8-12 Vue项目城市选择页 - 使用keep-alive优化网页性能
YananNi
2018-05-28
import HomeHeader from './components/header' import HomeSwiper from './components/swiper' import HomeIcons from './components/icons' import HomeRecomment from './components/recomment' import HomeGo from './components/go' import Axios from 'axios' import { mapState } from 'vuex' export default { name:"Home", components:{HomeHeader,HomeSwiper,HomeIcons,HomeRecomment,HomeGo}, data (){ return { swiperList:[], iconList:[], recommendList:[], weekendList:[] } }, computed: { ...mapState(['city']) }, methods:{ ajaxIndex () { Axios.get('/api/index.json?city=' + this.city).then(this.respones) }, respones (res) { console.log(res); const list=res.data.data; this.city=list.city this.swiperList=list.swiperList this.iconList=list.iconList this.recommendList=list.recommendList this.weekendList=list.weekendList } }, mounted () { this.lostcity = this.city this.ajaxIndex() }, activated () { if (this.lostcity !== this.city) { this.lostcity = this.city this.ajaxIndex() } } }
报错:Computed property "city" was assigned to but it has no setter.
程序正常运行
写回答
3回答
-
computed: {
...mapState(['city'])
},
改为:定义一个CurrentCity:‘city', 原因未知,有点奇怪
computed: {
...mapState({CurrentCity:‘city'})
},
042020-08-20 -
kopa
2020-08-03
this.city=list.city
删除掉, 因为json里面的city已经删除了00 -
行走在孤岭中
2019-09-02
你在这个 respones (res)请求返回中this.city=list.city删除吧,就没事了
00
相似问题