代码成就万世基积沙镇海,梦想永在凌云意意|

又一岁荣枯

园龄:3年4个月粉丝:11关注:6

this.$refs使用方法

this.$refs

vueref可以以属性的形式添加给标签或者组件

ref 写在标签上时:this.$refs.ipt 获取的是添加了ref="ipt"标签对应的dom元素

ref 写在组件上时:this.$refs['component'] 获取到的是添加了ref="component"属性的这个组件

<template>
 //给标签使用
    <input type="text" ref="ipt"/>
 //给组件使用
    <comp-detail ref="component"></list-detail>
    <button @click="confirm">确定</button>
</template>
methods:{
    confirm(){
        console.log(this.$refs.ipt.value)  //打印出输入框中的value值
        this.$refs['component'].init()     //调用组件comp-detail中的init()方法
     }
}

本文作者:又一岁荣枯

本文链接:https://www.cnblogs.com/java-six/p/16477553.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   又一岁荣枯  阅读(1466)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起