加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

浅谈Vue.js中ref ($refs)用法举例总结

发布时间:2020-12-17 02:40:17 所属栏目:百科 来源:网络整理
导读:本文介绍了Vue.js中ref ($refs)用法举例总结,分享给大家,具体如下: 看Vue.js文档中的ref部分,自己总结了下ref的使用方法以便后面查阅。 一、ref使用在外面的组件上 HTML 部分 ref在外面的组件上 js部分 我是子组件 " }; var refoutsidecomponent=new Vue

本文介绍了Vue.js中ref ($refs)用法举例总结,分享给大家,具体如下:

看Vue.js文档中的ref部分,自己总结了下ref的使用方法以便后面查阅。

一、ref使用在外面的组件上

HTML 部分

ref在外面的组件上

js部分

我是子组件
" }; var refoutsidecomponent=new Vue({ el:"#ref-outside-component",components:{ "component-father":refoutsidecomponentTem },methods:{ consoleRef:function () { console.log(this); // #ref-outside-component vue实例 console.log(this.$refs.outsideComponentRef); // div.childComp vue实例 } } });

二、ref使用在外面的元素上

HTML部分

JS部分

我是子组件
" }; var refoutsidedom=new Vue({ el:"#ref-outside-dom",components:{ "component-father":refoutsidedomTem },methods:{ consoleRef:function () { console.log(this); // #ref-outside-dom vue实例 console.log(this.$refs.outsideDomRef); //

ref在外面的元素上

} } });

三、ref使用在里面的元素上---局部注册组件

HTML部分

ref在里面的元素上

JS部分

" + "
我是子组件
" + "
",methods:{ consoleRef:function () { console.log(this); // div.childComp vue实例 console.log(this.$refs.insideDomRef); //
我是子组件
} } }; var refinsidedom=new Vue({ el:"#ref-inside-dom",components:{ "component-father":refinsidedomTem } });

四、ref使用在里面的元素上---全局注册组件

HTML部分

JS部分

" + "" + "

ref在里面的元素上--全局注册

" + "
",methods:{ showinsideDomRef:function () { console.log(this); //这里的this其实还是div.insideFather console.log(this.$refs.insideDomRefAll); // var refinsidedomall=new Vue({
el:"#ref-inside-dom-all"
});

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读