首页 > 解决方案 > 参考错误:文档未在 nativescript-vue 中定义

问题描述

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

它显示文档未定义错误

标签: vue.jsvuejs2vue-componentnativescript

解决方案


您在本机移动应用程序中使用 Web 技术。获取元素 id 的最佳方法是给元素一个 ref 并执行以下操作:

 const textField = this.$refs.groceryTextField.nativeView

这个 repo 中有很多很好的例子:https ://github.com/tralves/groceries-ns-vue/你也可以查看市场以获取更多代码示例:market.nativescript.org


推荐阅读