Push 路由的時(shí)候 顯示push undefined,請(qǐng)問是怎么回事
就在我添加數(shù)據(jù),改變路由的時(shí)候,報(bào)錯(cuò)了
代碼:
<template>
<div>
<p>標(biāo)題</p>
<input type="text" v-model="title">
<p>內(nèi)容</p>
<input type="text" v-model="content">
<div class="btn" @click="add()">添加</div>
</div>
</template>
<script>
import store from '@/store'
export default {
name: 'Add',
data () {
return {
title: '',
content: ''
}
},
methods: {
add() {
store.commit('addItem', {
title: this.title,
content: this.content
})
this.title = ''
this.content = ''
this.$router.push('/home/list')
}
}
}
</script>
<style scoped>
</style>
2019-05-06
router的push方法里面是一個(gè)對(duì)象,不是字符串。this.$router.push({ path: '/home/list'})