参考错误:未在nativescript-vue中定义文档

时间:2019-02-17 16:23:40

标签: vue.js vuejs2 vue-component nativescript

var elements = document.getElementsByClassName('active');
while(elements.length > 0){
    elements[0].classList.remove('active');
}
$event.target.classList.add('active');

它显示文档未定义错误

1 个答案:

答案 0 :(得分:3)

您正在本机移动应用程序中使用网络技术。获取元素ID的最佳方法是为您的元素提供ref并执行以下操作:

 const textField = this.$refs.groceryTextField.nativeView

此仓库中有很多很好的例子:https://github.com/tralves/groceries-ns-vue/,您也可以在市场上查看更多代码示例:market.nativescript.org