vue.js - 参考错误:文档未在 nativescript-vue 中定义
问题描述
var elements = document.getElementsByClassName('active');
while(elements.length > 0){
elements[0].classList.remove('active');
}
$event.target.classList.add('active');
它显示文档未定义错误
解决方案
您在本机移动应用程序中使用 Web 技术。获取元素 id 的最佳方法是给元素一个 ref 并执行以下操作:
const textField = this.$refs.groceryTextField.nativeView
这个 repo 中有很多很好的例子:https ://github.com/tralves/groceries-ns-vue/你也可以查看市场以获取更多代码示例:market.nativescript.org。
推荐阅读
- rust - 如何使用 proc 宏来创建可能违反卫生的宏?
- javascript - Jquery选项卡在淡入淡出动画之前发生变化
- javascript - Angular:使用firebase DB的传单更新标记位置
- javascript - 访问 DOM 加载后附加的元素
- javascript - 在提供文件之前如何等待 Python shell 执行
- python - 在多个类中自动更新变量
- visual-studio-code - 如何设置 VS Code Live Server 扩展以在 Linux 上使用 Firefox Developer?
- javascript - React:为什么我在 React 组件中的链接不像在纯 HTML 页面中那样工作?
- python - 如何从零开始按升序获取bar y轴
- python - 如何在 python 中水合推文 ID 的数据框