vue ref操作

Posted jiahaojava

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vue ref操作相关的知识,希望对你有一定的参考价值。

                         ref 获取组件的信息

技术分享图片

 



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
    <title>Title</title>
<script src="../vue.js"></script>
</head>
<body>
<div id="app">
<button @click="getEl">getEL</button>
<h3 ref="myh3">今天天气还不错!!!</h3>
<hr/>
<login ref="mylogin"></login>
</div>
</body>
<script>
var login ={
template:"<h3>我是子组件</h3>",
data(){
return {
mes:"我是之组件数据"
}
},
methods:{
show(){
console.log("我是之组件方法");
}
}
}
var vm = new Vue({
el: "#app",
data: {
mes: "hello Vue"
},
methods: {
getEl() {
console.log(this.$refs.myh3.innerHTML);
console.log(this.$refs.mylogin.mes);
this.$refs.mylogin.show();
}
},
components:{
login
}
});
</script>
</html>















































以上是关于vue ref操作的主要内容,如果未能解决你的问题,请参考以下文章

vue中ref的用法

vue组件操作 ---ref --v-model 2018-11-05

Vue 操作原生Dom refs

在typeScript+vue项目中使用ref

vue ref操作

在typeScript+vue项目中使用ref