【问题标题】:vue router $this not definedvue 路由器 $this 未定义
【发布时间】:2017-01-20 23:56:54
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

    $this不存在,需要使用this

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

    【讨论】:

      猜你喜欢
      • 2021-11-28
      • 2020-05-26
      • 2023-03-06
      • 2021-09-11
      • 2019-02-05
      • 1970-01-01
      • 2019-12-02
      • 2021-08-21
      • 1970-01-01
      相关资源
      最近更新 更多