完整报错:
vuexError in v-on handler: “TypeError: this.saveSearch is not a function”
报错原因:
...mapMutations(['saveSearch']),
这行写错位置了
要写在methods里面
正确的位置:
methods: {
search () {
console.log(this.select)
if (this.select === 1) {
// this.saveUser(this.state, {uid: this.input})
this.saveSearch({sname: this.input})
} else if (this.select === 2) {
this.saveSearch({sname: null, sauthor: this.input, sid: null, scate: null})
} else {
this.saveSearch({sid: this.input})
}
this.$router.push('/search')
},
...mapMutations(['saveSearch'])
}
浪费了半个小时