首页 > 其他分享 >ref属性

ref属性

时间:2023-06-18 20:22:34浏览次数:33  
标签:School console log DOM refs font ref 属性

  <!-- ref属性
  1.被用来给元素或子组件注册引用信息(id的替代者)
  2.应用在html标签上获取的是真实的DOM元素,应用在组件标签上是组件实例对象 -->
<template>
  <div id="app">
    <h2 v-text="msg" ref="title" hh="哈哈"></h2>
    <button @click="show" ref="btn">点我一下</button>
    <School ref="sch"></School>
  </div>
</template>

<script>
import School from './components/school'

export default {
  name: 'App',
  components: {
    School
  },
  data(){
    return{
      msg: '你好啊'
    }
  },
  methods: {
    show(){
      console.log(this.$refs.title);//真实DOM元素
      console.log(this.$refs.btn);//真实DOM元素
      console.log(this.$refs.sch);//School组件的实例对象
    }
  },
}
</script>

<style>
/* #app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
} */
</style>

 

标签:School,console,log,DOM,refs,font,ref,属性
From: https://www.cnblogs.com/ixtao/p/17489696.html

相关文章

  • 属性篇
    导入直接importimportmodule1[,module2[,...moduleN]frommoudleimportXXfromfiboimport*  主函数:__name__属性:每个模块(.py文件)都有一个__name__属性,当 ......
  • 基类属性如何反序列化表示具体类的Json字符串
    JsonConverter可以决定类型如何被序列化或反序列化。接口属性被反序列化时,会抛出异常,因为接口没有构造函数。JsonConvert.DeserializeObject<IVehicle>("Json字符串");JsonConvert.DeserializeObject<List<IVehicle>>("Json字符串");JsonConvert.DeserializeObject<Worker>(......
  • transition-property属性改变元素背景色。
    未使用transition-property属性前使用transition-property属性后面代码如下:<html<!doctypehtml><html><head><metacharset="utf-8"><title>transition-property属性</title><styletype="text/css">//引用css文件div......
  • vue3+vite+web3.js报错ReferenceError: process is not defined
    在vite最新版本中使用web3会报错只需要在vite.config.ts添加如下代码即可解决报错import{fileURLToPath,URL}from'node:url'import{defineConfig}from'vite'importvuefrom'@vitejs/plugin-vue'//引入import{resolve}from'path'export......
  • Cannot Reference “XxxClass.xxxmember” Before Supertype Constructor Has Been Ca
    在调用超类型构造函数之前无法引用“XxxClass.xxx”-----在一个类的构造器方法还未执行的时候,我们无法使用这个类的成员属性或成员方法。百度翻译:在调用超类型构造函数之前无法引用“XxxClass.xxx”-----我的理解:在一个类的构造器方法还未执行的时候,我们......
  • css文字换行white-space属性
    这个文章解释的很细致:white-space属性被指定为从下面的值列表中选择的单个关键字。normal连续的空白符会被合并,换行符会被当作空白符来处理。换行在填充「行框盒子(lineboxes)」时是必要。nowrap和normal一样,连续的空白符会被合并。但文本内的换行无效。pre连......
  • CMakeLists --- 指定安装目录 CMAKE_INSTALL_PREFIX
    cmake指定makeinstall时的安装目录:通过设置CMAKE_INSTALL_PREFIX的值来控制。有两种方法:1.在执行cmake时,指定安装目录:cmake-DCMAKE_INSTALL_PREFIX=/xxx/x..2.直接在CMakeLists.txt中设置set(CMAKE_INSTALL_PREFIX/xxx/x) 编译完成后,执行makeinstall即可。......
  • Weak References in .NET
    今天看到一个老外,用C#代码讲WeakReferences的用法不过我发现它的例子应该是用毛病的,在它的例子中weakRef应该没有逃开作用域,不能被正确回收,所以例子的结果也是不准的末尾给出了我对其修改后的例子,给出了两种作用域的对比DecidingWhentoUseWeakReferencesin.NET ......
  • vue中this.$refs获取不到组件元素的解决办法
    vue中this.$refs获取不到组件元素的解决办法http://www.allyns.cn/info/162当我们在vue开发中遇到使用this.$refs报错获取不到组件元素时。<template><divclass="dataQueryEventGraphDialog"><hg-dialog:title="title":width="950":height="485&q......
  • C#对List的元素按属性排序
    C#对List元素排序有几种方法。方法一、使用LinqList<User>sortedList=list.OrderBy(o=>o.ID).ToList();如果按降序排序,可以使用OrderByDescending方法:List<User>sortedList=list.OrderByDescending(o=>o.ID).ToList();方法二、扩展IComparable接口示例:publiccl......