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官方

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

相关推荐
骑驴看星星a4 分钟前
数学建模--Topsis(Python)
开发语言·python·学习·数学建模
长安即是故里1 小时前
Maxwell学习笔记
笔记·学习
silent_missile1 小时前
element-plus穿梭框transfer的调整
前端·javascript·vue.js
★YUI★3 小时前
学习制作记录(选项UI以及存档系统)8.24
学习·游戏·ui·unity·c#
咸甜适中3 小时前
rust语言 (1.88) egui (0.32.1) 学习笔记(逐行注释)(十四)垂直滚动条
笔记·学习·rust·egui
yes or ok4 小时前
前端工程师面试题-vue
前端·javascript·vue.js
_Congratulate4 小时前
vue3高德地图api整合封装(自定义撒点、轨迹等)
前端·javascript·vue.js
页面仔Dony5 小时前
Vue2 与 Vue3 深度对比
vue.js·前端框架
It_张5 小时前
Building Systems with the ChatGPT API 使用 ChatGPT API 搭建系统(第五章学习笔记及总结)
笔记·学习·chatgpt
The_Second_Coming5 小时前
Linux 学习笔记 - 集群管理篇
linux·笔记·学习