首页 > 其他分享 >VUE使用Element-ui表达式拼接字符串 el-table-column的prop拼接字符串 拼接table 使用<template slot-scope="scope&quo

VUE使用Element-ui表达式拼接字符串 el-table-column的prop拼接字符串 拼接table 使用<template slot-scope="scope&quo

时间:2023-06-15 12:45:18浏览次数:53  
标签:prop yearsMonth 拼接 字符串 table data

VUE使用Element-ui表达式拼接字符串 el-table-column的prop拼接字符串 使用<template slot-scope="scope"> 更改td里面值
https://blog.csdn.net/WindNolose/article/details/125422409

描述

VUE中的标签属性,可以在属性前使用,让属性绑定到data中的动态数据
el-table-column标签可以使用prop配合:data实现表格渲染列表数据
业务需要我们对数据进行一些拼接的操作
比如月份,请求到的数据是纯数字,可是表格中应该显示 XX月才是正确的


表达式字符串拼接

这个其实很简单,直接使用加号即可,但是要注意单引号和双引号的区分
我们以:label为例,我们在城市后面拼接供电局字样
data数据:

    data() {
      return {
        city:""
      }
    },
  • 1
  • 2
  • 3
  • 4
  • 5

:label标签数据:

    <el-table-column :label="city + '供电局'" />
  • 1

效果:
在这里插入图片描述


table渲染绑定数据字符串拼接

如果是使用prop渲染的数据,那么字符串拼接上,只会认为这个值是你属性的值
正确的做法是使用template标签嵌套数据

我们以月份为例
data请求后的数据:

data() {
      return {
        allList:[
			{
				yearsMonth: 1
			},{
				yearsMonth: 2
			},{
				yearsMonth: 3
			},{
				yearsMonth: 4
			},{
				yearsMonth: 5
			},{
				yearsMonth: 6
			},{
				yearsMonth: 7
			},{
				yearsMonth: 8
			},{
				yearsMonth: 9
			},{
				yearsMonth: 10
			},{
				yearsMonth: 11
			},{
				yearsMonth: 12
			}
		]
      }
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

未拼接的标签:

<el-table :data="allList">
	<el-table-column  label="月份"  prop="yearsMonth"/>
</el-table>
  • 1
  • 2
  • 3

效果:
在这里插入图片描述
拼接后的标签:

<el-table :data="allList">
	<el-table-column label="月份" prop="yearsMonth">
	  <template slot-scope="scope">
	    {{scope.row.yearsMonth}}月
	  </template>
	</el-table-column>
</el-table>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

效果:
在这里插入图片描述

标签:prop,yearsMonth,拼接,字符串,table,data
From: https://www.cnblogs.com/sunny3158/p/17482554.html

相关文章

  • Wtm layui add form pop out and dispaly in tables
    #regionAddChargeItem[AllRights]//useineditpagepublicIActionResultAddChargeJob(stringid){varvm=Wtm.CreateVM<tbl_ma_dbn_jobListVM>();vm.SearcherMode=ListVMSearchModeEnum......
  • 每日一道leetcode:8. 字符串转换整数 (atoi)
    1.题目(中等)题目链接请你来实现一个myAtoi(strings)函数,使其能将字符串转换成一个32位有符号整数(类似C/C++中的atoi函数)。函数myAtoi(strings)的算法如下:读入字符串并丢弃无用的前导空格检查下一个字符(假设还未到字符末尾)为正还是负号,读取该字符(如果有)。确定最终结果......
  • Oracle drop table ... purge
    https://www.cnblogs.com/hider/p/12194675.html操作Oracle时,经常会删除一个表,当删除错误后,希望能够恢复该表,有时也希望删除表之后能够立刻释放表的空间。通过purge的使用可以在Oracle中删除表、恢复表和空间释放。droptable当在Oracle中删除(drop)一个表时,数据库不......
  • python基础知识——字符串
    1、字符串的格式化python将若干值插入到带有“%”标记的字符串中,实现动态地输出字符串。格式:"%s"%str"%s%s"%(str_1,str_2)例如:str_0="I"str_1="Love"str_2="China"format="%s%s%s"%(str_0,str_1,str_2)printformat#ILoveChi......
  • StringPtr StringPtrs 字符串指针 字符串指针切片
    funcBoolPtr(vbool)*bool{  return&v}funcStringPtr(vstring)*string{  return&v} funcStringPtrs(vals[]string)[]*string{  ptrs:=make([]*string,len(vals))  fori:=0;i<len(vals);i++{    ptrs[i]=&v......
  • mongo聚合字符串类型的数字进行排序
    设置collationCollationcollation=Collation.of(Locale.CHINESE).numericOrdering(true);设置聚合选项Aggregationaggregation=Aggregation.newAggregation(Aggregation.match(orOperator),).withOptions(AggregationO......
  • 图像拼接算法技术报告
    图像拼接算法技术报告代码介绍图像拼接是将多个图像按照一定的顺序和几何变换方法组合在一起,形成一个更大、更完整的图像的过程。通过图像拼接,可以将多个部分图像合并为一个整体,以展示更广阔的视野或提供更全面的信息。我们先感性地看一组实验结果(静态场景的图像拼接):左图......
  • 【数据结构和算法面试题】左旋转字符串
    问题分析:本题是常见的旋转字符串的问题,解决的方法是两步旋转的方法:方法:voiddo_reverse(char*p_start,char*p_end){ if(NULL==p_start||NULL==p_end||p_start>p_end)return; chartmp; while(p_start<p_end){ tmp=*p_start; *p_start=*p_end; *p_end......
  • 代码随想录算法训练营第七天| 344.反转字符串 、 541. 反转字符串II、 剑指Offer 05.
     344.反转字符串代码:1voidreverseString(vector<char>&s){23inti=0;4intj=s.size()-1;5while(i<j)6{7charmid=s[i];8s[i]=s[j];9s[j]=mid;1011i++;12......
  • PHP基础——字符串的常用操作
    在PHP中使用较多的是字符串的操作,字符串的常用操作主要有如下的几种:字符串的表示字符串的连接去除字符串中的空格和特殊字符字符串的比较分割字符串和合成字符串1、字符串的表示在PHP中,字符串有两种表示的方法:-单引号:”-双引号:”“如:<?php$str_1="Hello\n";......