-
概述
$refs可用于获取html对象,或Vue实例对象
-
使用
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Vue父子件数据传递(自定义v-model方式)</title> </head> <body> <div id="app"> <cmp ref="cmp"></cmp> <input type="button" ref="btn" value="获取cmp组件中的name属性" @click="getCmpName"> <h2>cmp组件name:{{ cmp_name }}</h2> <button @click="btnValCahnge('名称被修改了...')">修改上个按钮的名称</button> </div> <template id="cmp"> <h2>这是cmp组件</h2> </template> <script src="https:///npm/vue/dist/vue.js"></script> <script> let app = new Vue({ components:{ cmp: { template: '#cmp', data(){ return { name: 'com中的name' } } } }, data:{ cmp_name: '' }, methods:{ getCmpName() { this.cmp_name = this.$refs.cmp.name }, btnValCahnge(val){ this.$refs.btn.value = val } } }).$mount('#app') </script> </body> </html>
1. Vue $refs使用
原创
©著作权归作者所有:来自51CTO博客作者可乐不可的原创作品,请联系作者获取转载授权,否则将追究法律责任
Vue $refs使用
上一篇:1. Vue stop修饰符
下一篇:1. Vue 过滤器的使用

提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
基于ElementUI+html和VUE实现的java后台管理系统
基于Html+Elementui实现的java后台管理框架
Vue ELementUI+html Springboot Jfinal Shiro登录验证 -
vue中$refs的使用
vue中的$refs的使用
vue $refs -
Vue.js之$refs
尽管有 prop 和事件,但是有时仍然需要在 JavaScript 中直接访问子组件。为此可以使用 ref 为子组
vue vue-js ref ide h5 -
vue中$refs、,$emit、$on
et
javascript f5 -
vue $refs All In One
vue $refs All In One
vue js $refs 数据 html