1 Star 0 Fork 0

prcool/前端开发学习

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
组件6ref.html 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
prcool 提交于 2021-09-11 21:02 +08:00 . 前端开发学习
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<!-- 引入vue.js -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<h1 ref="mycom2">{{msg}}</h1>
<button @click="getElement">获取子组件元素</button>
<com1 ref="mycom1"></com1>
</div>
<template id = "temp1">
<div>
<h1>子组件: {{m}}</h1>
<button >子组件按钮</button>
</div>
</template>
</body>
<script>
// 实例化vue对象
let vm = new Vue({
// 绑定对象
el:'#app',
data:{
msg:'hello vue.js'
},
methods:{
getElement(){
this.$refs.mycom1.m='子组件的值被父组件获取并修改'
console.log(this.$refs.mycom2.innerText)
}
},
components:{
com1:{
template:'#temp1',
data:function(){
return {
m:'我是子组件的数据'
}
}
}
}
})
</script>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/prcool/front-end-development-learning.git
git@gitee.com:prcool/front-end-development-learning.git
prcool
front-end-development-learning
前端开发学习
master

搜索帮助