[英]Select DOM element via VueJS
I wrote a Chromium extension using clear JavaScript to interact with the DOM, but now I study VueJS and rewrote the extension to use Vue. 我使用清晰的JavaScript与DOM交互编写了一个Chromium扩展,但是现在我学习了VueJS并重写了该扩展以使用Vue。 I found one problem: there is one
<input>
element connected to Vue. 我发现了一个问题:Vue连接了一个
<input>
元素。
I change its value via the bg.cp
property of the Vue instance, and now I need to select the DOM element. 我通过Vue实例的
bg.cp
属性更改其值,现在我需要选择DOM元素。 Is there any way to make text selection using the Vue instance instead of using document.getElementById('test').select()
? 有什么方法可以使用Vue实例而不是
document.getElementById('test').select()
进行文本选择吗?
The final goal is to copy the <input>
field to clipboard. 最终目标是将
<input>
字段复制到剪贴板。
<body>
<div id="appBg">
<input v-model="cp" id="test">
</div>
<script>
//vue instance of div with input field
var bg = new Vue({
el: "#appBg",
data: {
cp: ""
}
});
</script>
</body>
you can use ref in DOM attribute and call it by $refs in js section 您可以在DOM属性中使用ref,并在js部分中通过$ refs调用它
EX: 例如:
<input ref="inputName" />
and in js section call 并在js部分调用
this.$refs.inputName
here you can read explanation of it 在这里你可以阅读它的解释
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.