vue.js'document.getElementById'速记 [英] vue.js 'document.getElementById' shorthand
本文介绍了vue.js'document.getElementById'速记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
vue.js是否像JQuery的$('#id')
一样是document.getElementById('#id')
的缩写?
Does vue.js have a shorthand for document.getElementById('#id')
like JQuery's $('#id')
?
如果是这样,文档中对此的引用在哪里,以便我可以找到其他信息?
If so, where is the reference for this in the docs so I can locate other information?
推荐答案
vue 2中没有捷径.
Theres no shorthand way in vue 2.
Jeff的方法似乎在vue 2中已被弃用.
Jeff's method seems already deprecated in vue 2.
这里是您实现目标的另一种方式.
Heres another way u can achieve your goal.
var app = new Vue({
el:'#app',
methods: {
showMyDiv() {
console.log(this.$refs.myDiv);
}
}
});
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
<div id='app'>
<div id="myDiv" ref="myDiv"></div>
<button v-on:click="showMyDiv" >Show My Div</button>
</div>
这篇关于vue.js'document.getElementById'速记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文