$refs的基本用法vue
一個對象(Object),持有註冊過 ref
特性 的全部 DOM 元素和組件實例。api
<template> <view class="container" style="background: #0FAEFF;"> <view class="child"> hi {{showModal}}</view> </view> </template> <script> export default { props: { showModal: { type: String, default: 'hello' } }, data() { return { childdata: 'child value' }; }, methods: { sayHello() { console.info("--child:--" + this.showModal); } } } </script>
<template> <view class="container"> <child :showModal="showModal" ref="vref"></child> <button @tap="refMethods" type="primary" >點擊</button> </view> </template> <script> import child from "../../components/child.vue" export default { components: { child }, data() { return { showModal: " parent say", parentValue: '', syncDate: ' p syncDate' }; }, methods: { refMethods() { var child = this.$refs.vref; child.sayHello(); } } } </script> <style> </style>