Vue.js2:如何重用组件内

时间:2017-09-08 21:24:14

标签: ecmascript-6 vue.js vuejs2 vue-component

所以我想在mount函数中定义一个const值。并希望在vue组件的方法中使用此const值。

示例:

export default {
    name : 'app',
    data(){

    },
    mounted(){
        // Constant refThis is defined here which gets the reference to this vue component 
        const refThis = this;

    },
    methods:{
        useThisRef() {
            // I want to be able to use the refThis here 
        }
    }
}

如何在vue组件的其他部分中引用refThis?

1 个答案:

答案 0 :(得分:-1)

你可以在const.js文件中执行某些操作:

export const ConstName = {
  //Code in here
}

然后你可以在顶部的任何组件中导入它:

import ConstName form '/path/to/const.js