1

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

1 回答 1

4

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

export default { 
    data() {
        return {
            histories: []
        }
    },
    route: {
        activate() {
            this.getHistories()
        }
    },
    methods: {
        getHistories() {
            this.histories = store.getHistories()
        }
    }
}
于 2016-09-13T12:00:58.130 回答