【发布时间】:2018-02-17 20:49:06
【问题描述】:
所以我想在挂载的函数中定义一个 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 的引用?
【问题讨论】:
-
你好像有an XY problem,请解释一下你到底想做什么。
-
@Nit 感谢您对 XY 问题的启发。我已经相应地编辑了问题。
-
既然有
this,为什么还需要refThis? -
很抱歉应该在问题中提到这一点,但有时直接使用它时它不会返回属性。 @伯特
-
你的意思是在回调中?
标签: ecmascript-6 vue.js vuejs2 vue-component