2022-11-13 19:15阅读: 52评论: 0推荐: 0

【Vue2-02】ref属性

ref属性

  1. 被用来给元素或子组件注册引用信息(id的替代者)
  2. 应用在html标签上获取的是真实DOM元素,应用在组件标签上是组件实例对象(vc)
  3. 使用方式:
    • 打标识:<h1 ref="xxx">...</h1><School ref="xxx"></School>
    • 获取:this.$refs.xxx
<template>
  <div>
    <h1 ref="title">获取标题dom元素</h1>
    <School ref="sch"></School>
    <button @click="show">点我输出上方DOM元素</button>
  </div>
</template>

<script>
  // 引入组件
  import School from './components/School.vue'

  export default {
    name: 'App',
    // 注册组件
    components: {
      School,
    },
    methods: {
      show() {
        console.log(this.$refs.title);
        console.log(this.$refs.sch);
      }
    },
  }
</script>

<style scoped>

</style>

本文作者:Ac_c0mpany丶

本文链接:https://www.cnblogs.com/keyongkang/p/16886669.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Ac_c0mpany丶  阅读(52)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 You Are My Sunshine REOL
You Are My Sunshine - REOL
00:00 / 00:00
An audio error has occurred.

作曲 : Traditional

You are my sunshine

My only sunshine.

You make me happy

When skies are gray.

You'll never know, dear,

How much I love you.

Please don't take my sunshine away

The other night, dear,

When I lay sleeping

I dreamed I held you in my arms.

When I awoke, dear,

I was mistaken

So I hung my head and cried.

You are my sunshine,

My only sunshine.

You make me happy

When skies are gray.

You'll never know, dear,

How much I love you.

Please don't take my sunshine away.

You are my sunshine,

My only sunshine

You make me happy

When skies are gray.

You'll never know, dear

How much I love you

Please don't take my sunshine away

Please don't take my sunshine away.

Please don't take my sunshine away.