如何在vue js中重用es6类? [英] how to reuse es6 class in vue js?
本文介绍了如何在vue js中重用es6类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Vue Js中重用一些现有的ES6类.
How to reuse some existing ES6 classes in Vue Js.
有一个类,其中的变量正在被Observable更新.
Have a class which has a variable being updated by observable.
class A {
public a: string;
someobservable.subscribe((a) =>{
this.a = a;
})
}
在vue.JS中创建了此类的对象.
In vue.JS have created the object of this class.
示例如何使用属性:
created: {
objA = new A();
}
methods: {
getA() {
if(this.objA !== undefined){
return objA.a;
}
}
}
和在vue模板中:
<div>{{getA()}}</div>
模板中的值与类中变量的值不同步.
还有其他使用Vue模板的属性的方法,它可以实时更新.
Is there any other way to use the property in Vue template that it keeps updating real time.
推荐答案
它应与 getA()
一起使用,作为计算的属性而不是方法.另外,您可以跳过if语句,因为没有return语句将返回 undefined
.
It should work with getA()
as a computed property rather than a method. Also, you can skip the if statement as no return statement will return undefined
.
computed: {
getA() {
return objA.a;
}
}
这篇关于如何在vue js中重用es6类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文