vue怎么获取DOM节点?
发布于 2021-01-11 17:01:34
关注者
0
被浏览
408
4 个回答
-
<template> <div> <input ref="myInput" type="text" value="hello world"> <button @click="getText">getText</button> </div> </template> <script> export default { methods: { getText() { const input = this.$refs.myInput console.log(input) alert(input.value) } } } </script>
-
1、document.getElementById("id")
2、this.$refs.xx还有一些特殊的,比如this.$root、this.$parent、this.$children