名称 | 描述 |
---|---|
$data | 组件实例正在侦听的数据对象。 |
$props | 当前组件接收到的 props 对象。 |
$refs | 一个对象,持有注册过 ref attribute 的所有 DOM 元素和组件实例。 |
$attrs | 包含了父作用域中不作为组件 props 或自定义事件的 attribute 绑定和事件。 |
$refs
- 一个对象,持有注册过 ref attribute 的所有 DOM 元素和组件实例。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>v-slot</title> </head> <body> <div id="root"> </div> <script src="https://unpkg.com/vue@next"></script> <script> const app = Vue.createApp({ mounted(){ console.log(this.$refs); this.$refs.common.say666(); }, template:` <commen-item ref='common' /> ` }); app.component('commen-item',{ methods:{ say666(){ console.log('666666'); } }, template: ` <div>hello</div> ` } ) const vm = app.mount('#root'); </script> </body> </html>