Vue+Element ui Study

目录

[一、Vue+Element ui](#一、Vue+Element ui)

1、show-overflow-tooltip属性设置宽度

[2、this.refs使用方法](#2、this.refs使用方法)

[Error in v-on handler: "TypeError: Cannot read properties of undefined (reading 'xxx')"](#Error in v-on handler: “TypeError: Cannot read properties of undefined (reading ‘xxx‘)“)


一、Vue+Element ui

1、show-overflow-tooltip属性设置宽度

:show-overflow-tooltip="true",该属性可以让内容在一行显示,如果显示不下时,显示...,并且鼠标划过时显示全部文字。

现在需求是:调整显示全部文字的宽度。

样式代码如下:可以在全局添加这样全部生效,如果不想加在全局的话,可以单独加在页面当中,但是切记修改elementui自带样式的话,不能在<style scoped></style>中修改,因为不会生效。

复制代码
<style lang="scss">
.el-tooltip__popper {
  max-width: 800px;
  //max-width: 60%;
}
</style>

2、this.$refs使用方法

this.$refs

在vue中ref可以以属性的形式添加给标签或者组件

ref 写在标签上时:this.$refs.editValue 获取的是添加了ref="editValue"标签对应的dom元素

ref 写在组件上时:this.$refs['component'] 获取到的是添加了ref="component"属性的这个组件

复制代码
<template>
 //给标签使用
    <input type="text" ref="editValue"/>
 //给组件使用
    <comp-detail ref="component"></comp-detail>
    <button @click="confirm">确定</button>
</template>

methods:{
    confirm(){
        console.log(this.$refs.editValue.value)  //打印出输入框中的value值
        this.$refs['component'].init()     //调用组件comp-detail中的init()方法
     }
}

-----使用过程我报错如下

Error in v-on handler: "TypeError: Cannot read properties of undefined (reading 'xxx')"

翻译大概就是:

v-on处理程序中出现错误:"TypeError:无法读取未定义的属性(读取'xxx')"

但是,实际上我是调用自定义组件中的方法

解决方案:

原因是因为调用方法的时候,实际值虽然初始化了,但是实际上还没渲染到dom上,因此应该改使用nextTick,即等元素被初始化成功后才进行调用方法。

复制代码
this.dialogVisible =true
this.$nextTick(()=>{
    this.$refs.component.setValue('你好')   //调用setValue方法
})

Element官方

天下事有难易乎?为之,则难者亦易矣;不为,则易者亦难矣。

相关推荐
chancygcx_2 分钟前
前端框架Vue3(二)——Vue3核心语法之OptionsAPI与CompositionAPI与setup
vue.js·前端框架
朱小弟cs65 分钟前
Orange的运维学习日记--23.Linux计划任务详解
linux·运维·学习
安卓开发者32 分钟前
Jetpack Compose for XR:构建下一代空间UI的完整指南
ui·xr
90后的晨仔1 小时前
🔍Vue 模板引用(Template Refs)全解析:当你必须操作 DOM 时
前端·vue.js
Hello小赵1 小时前
嵌入式硬件学习(十)—— LED驱动+杂项设备驱动
嵌入式硬件·学习
90后的晨仔1 小时前
👂 Vue 侦听器(watch)详解:监听数据的变化
前端·vue.js
W.KN1 小时前
Servlet 学习笔记
笔记·学习·servlet
90后的晨仔1 小时前
深入浅出 Vue 的 computed:不仅仅是“计算属性”那么简单!
前端·vue.js
Nan_Shu_6141 小时前
学习:入门uniapp Vue3组合式API版本(17)
前端·vue.js·学习·uni-app
hunteritself2 小时前
DeepSeek 论文夺冠,智谱开源 GLM-4.5,OpenAI 学习模式上线!| AI Weekly 7.28-8.3
人工智能·学习·chatgpt·开源·bug·powerpoint