我正在使用vue-router,在其中一个组件/ vue中,我尝试在加载特定组件时从数据库加载历史事务:
<script>
import store from '../store'
export default {
data() {
return {
histories: []
}
},
route: {
activate() {
$this.getHistories()
}
},
methods: {
getHistories() {
$this.histories = store.getHistories()
}
}
}
</script>
我收到了这两个错误:
build.js:12642 [vue-router] Uncaught error during transition:
build.js:28551 Uncaught ReferenceError: $this is not defined
答案 0 :(得分:4)
$this
不存在,您需要使用this
:
export default {
data() {
return {
histories: []
}
},
route: {
activate() {
this.getHistories()
}
},
methods: {
getHistories() {
this.histories = store.getHistories()
}
}
}