zoukankan      html  css  js  c++  java
  • vue在el-dialog中this.$refs值为undefined问题

    vue中元素上加上ref属性取值,相当于取整个元素的,和$("#id")类似。但是要用此属性需要了解加载的时间,从官网上可以看到

    关于 ref 注册时间的重要说明:因为 ref 本身是作为渲染结果被创建的,在初始渲染的时候你不能访问它们 - 它们还不存在!$refs 也不是响应式的,因此你不应该试图用它在模板中做数据绑定。

    一般用法就是在mounted方法中加入this.$nextTick

    具体例子

    <el-input ref="childShow" />

      mounted() {
        this.$nextTick(() => {
          if (this.$refs.childShow !== undefined) {
            this.$refs.childShow.setTree('0000', '', '')
          }
        })
    }

    但是如果$refs在el-dialog中用上述方法还是会undefined

    解决的方法就是在el-dialog中加入回调函数@open,然后在回调函数方法中用this.$nextTick。

  • 相关阅读:
    OpenGL Pixel Linked-List
    Unity multi_compile
    Bindless Textures
    chmod递归设置文件属性
    push submodule
    NodeJS Debugger
    重载new操作符
    OpenGL瓶颈
    NGUI架构和Draw Call合并原理
    字符串哈希函数(String Hash Functions)
  • 原文地址:https://www.cnblogs.com/feipengting/p/14041300.html
Copyright © 2011-2022 走看看