vue router $这个没有定义

时间:2016-09-13 11:36:48

标签: vue.js vue-component vue-router

我正在使用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

1 个答案:

答案 0 :(得分:4)

$this不存在,您需要使用this

export default { 
    data() {
        return {
            histories: []
        }
    },
    route: {
        activate() {
            this.getHistories()
        }
    },
    methods: {
        getHistories() {
            this.histories = store.getHistories()
        }
    }
}