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回答

qq_Mason舟_0

2018-05-30

computed: {

  ...mapState(['city'])

 },

改为:定义一个CurrentCity:‘city', 原因未知,有点奇怪

computed: {

  ...mapState({CurrentCity:‘city'})

 },


0
4
慕瓜4376983
\(^o^)/
2020-08-20
共4条回复

kopa

2020-08-03

this.city=list.city
删除掉, 因为json里面的city已经删除了

0
0

行走在孤岭中

2019-09-02

你在这个 respones (res)请求返回中this.city=list.city删除吧,就没事了

0
0

Vue2.5-2.6-3.0开发去哪儿网App 零基础入门到实战

课程紧跟Vue3版本迭代,企业主流版本Vue2+Vue3全掌握

10675 学习 · 8191 问题

查看课程