亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Ant design vue中的聯(lián)動(dòng)選擇取消操作

 更新時(shí)間:2020年10月31日 15:23:45   作者:知所云  
這篇文章主要介紹了Ant design vue中的聯(lián)動(dòng)選擇取消操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

項(xiàng)目中會(huì)遇到需求就是table表格中選中在側(cè)邊展示,側(cè)邊刪除,table中選中取消的聯(lián)動(dòng)選中

ui框架:Ant design vue

組件:table 和 tag

html中

<template v-for="tag in dataType">
 <!-- key不能使用index -->
 <a-tag :key="tag.id" closable :afterClose="() => deleteDataType(tag.id)">{{tag.title}}</a-tag>
</template>
<a-table 
 :rowSelection="rowSelection()" 
 :columns="columns" 
 :dataSource="filterTypeData" 
 :pagination="paginationProps" :scroll='{y:455}' >
 <template slot="dataName" slot-scope="dataName">
  <div v-for="(list,index) in dataName" :key='index'>{{list.name}}</div>
 </template>
 <template slot="description" slot-scope="description">
  <div v-for="(list,index) in description" :key='index'>{{list.content}}</div>
  </template>
</a-table>

js代碼

在table中如果想要某個(gè)單元格里面是呈現(xiàn)兩行或者兩行以上,那么就添加template 讓slot=命名,將數(shù)據(jù)循環(huán)遍歷就可以呈現(xiàn)了

data:{
return{
 const columns = [
 {
  title: '數(shù)據(jù)類型',
  dataIndex: 'dataTypeName',
  width: '15%'
 },
 {
  title: '數(shù)據(jù)名稱',
  dataIndex: 'dataName',
  width: '15%',
  scopedSlots: { customRender: 'dataName' }
 },
 {
  title: '數(shù)據(jù)描述',
  dataIndex: 'description',
  scopedSlots: { customRender: 'description' }
 }
 ],
 rowKeys:[],
 dataType:[],
 changeDataType:[],
 addDataType:[],
 rowKeys:[],
 showTip:false // 是否禁止選擇(如果最多選擇8條)
}
}

頁面為

rowSelection() {
  // const selectedRowKeys = this.selectedRowKeys
  const self = this
  return {
  columnTitle: '選擇', // 去掉頭部全選框
  hideDefaultSelections: true,
  // selections: { key: 1 },
  selectedRowKeys: self.rowKeys, // 選中的key值
  onChange: (selectedRowKeys, selectedRows) => {
   // 勾選改變觸發(fā)事件
   if (selectedRows.length <= 7) {
   self.changeDataType = selectedRows
   self.addDataType()
   this.showTip = false
   } else {
   // self.$message.error('數(shù)據(jù)最多選擇8個(gè)')
   this.showTip = true
   }
  }
  }

在table中插入選擇框,想要將頭部全選框去掉直接在rowSelection中設(shè)置columnTitle: ‘選擇';selectedRows是勾選中的數(shù)組集合,selectedRowKeys是選中內(nèi)容中的key值,可以通過將id設(shè)置成key就可以了

如果要做到連動(dòng)選擇,其主要的就是selectedRowKeys和selectedRows,將勾選的selectedRows賦值給側(cè)邊的數(shù)據(jù)

deleteDataType(removedTag) {
  // 側(cè)邊數(shù)據(jù)刪除
  const { rowKeys } = this
  const newArr = []
  this.rowKeys = []
  // tag標(biāo)簽close事件是diaplay:none到dome元素上,所有需要用到afterClose key不能使用index,否則刪除事件有問題
  const tags = this.dataType.filter(tag => tag.id !== removedTag)
  this.dataType = tags
  rowKeys.forEach(list => {
  if (list !== removedTag) {
   newArr.push(list)
  }
  })
  this.rowKeys = [...newArr]
 },
addDataType() {
  // 勾選列表數(shù)據(jù)
  this.dataType = []
  this.rowKeys = []
  console.log(this.changeDataType)
  this.changeDataType.forEach(list => {
  if (list.templateItemId && list.selectItem) {
   // 初始化的時(shí)候
   this.dataType.push({ title: list.dataTypeName, id: list.templateItemId })
   this.rowKeys.push(list.templateItemId)
  }
  if (list.key) {
   // 點(diǎn)擊多選的時(shí)候
   this.dataType.push({ title: list.dataTypeName, id: list.key })
   this.rowKeys.push(list.key)
  }
  })
 },

補(bǔ)充知識(shí):ant-design-vue的select二級(jí)聯(lián)動(dòng),聯(lián)動(dòng)文本不更新的解決辦法

前言

有了需要改動(dòng)祖?zhèn)鞔a項(xiàng)目需求:把之前的select改成二級(jí)聯(lián)動(dòng)。項(xiàng)目使用了ant-design-vue,數(shù)據(jù)為[{"id":1,"name":"前端開發(fā)"}]

問題描述

<a-form :form="form" @submit="handleCreateMenuSubmit">
 <a-select style="width:50%" placeholder="請選擇技術(shù)領(lǐng)域" @change="handleNoteCategoryChange">
 <a-select-option v-for="item in note_category" :key="item.id">
{{ item.name }}
 </a-select-option>
 </a-select>
 <a-select style="width:50%" placeholder="請選擇分類" ref="note_category2" @change="handleNoteCategoryChange2">
 <a-select-option v-for="item in note_category2" :key="item.id">
{{ item.name }}
 </a-select-option>
 </a-select>
 <a-form-item label="簡介">
 <a-textarea
placeholder="如:產(chǎn)品設(shè)計(jì)與研發(fā)"
v-decorator="['description']"
:auto-size="{ minRows: 2, maxRows: 4 }"
 />
 </a-form-item>
</a-form> 


handleNoteCategoryChange(value, option) {
 Axios.post(this.userData.noteUrl + 'get_note_category_by_pid',{
 pid: value
 })
 .then((res) => {
 if (res.data.code == 1) {
 this.note_category2 = res.data.data;
 } else if(res.data.code == 0) {
 this.note_category2 = [];//獲取成功,但是數(shù)據(jù)為空
   this.note_category2Id = -1,
 } else {
 this.$message.error(res.data.msg);
 }
 })
 .catch(() => this.$message.error('請檢查網(wǎng)絡(luò)后重試'));
},
handleNoteCategoryChange2(value, option) {
 this.note_category2Id = value;
},
 
//-------------------------------
data(){
 return {
  note_category: [],
  note_category2: [], 
  note_category2Id: -1,
 }
}

當(dāng)我切換了一級(jí)下拉框,二級(jí)下拉框的數(shù)據(jù)也重新賦值啦,但是二級(jí)下拉框選中的文本依舊沒有改變。

第一次選了一級(jí)“前端開發(fā)”,選擇了二級(jí)“百度小程序”,此時(shí)切換一級(jí)為“數(shù)據(jù)庫”,二級(jí)的數(shù)據(jù)被重新賦值,但是此時(shí)二級(jí)的文本依然是之前選擇的“百度小程序”。

解決方案

首先懷疑是屬于特殊方法操作了數(shù)組,導(dǎo)致無法更新數(shù)據(jù)到UI,于是使用this.$forceUpdate()強(qiáng)制渲染。但是結(jié)果不如意,沒效果。

然后使用了this.$set(this.note_category2,0,{"id":0,"name":"請選擇分類"}),但是依然沒有效果。

難受,使用了最原始簡單暴力的方法,直接修改文本吧。代碼如下:

 handleNoteCategoryChange(value, option) {
 console.log(value);
 // 獲取note_category筆記分類
 Axios.post(this.userData.noteUrl + 'get_note_category_by_pid',{
 pid: value
 })
 .then((res) => {
 if (res.data.code == 1) {
  this.note_category2 = res.data.data;
 } else if(res.data.code == 0) {
  this.note_category2 = [];
  this.note_category2Id = -1;
  if (this.$refs.note_category2.$el.children[0].children[0].children[1]) {
this.$refs.note_category2.$el.children[0].children[0].children[1].innerText = '請選擇分類';
  }
 } else {
  this.$message.error(res.data.msg);
 }
 })
 .catch(() => this.$message.error('請檢查網(wǎng)絡(luò)后重試'));

 },

不愉快的收工。不知道大家有沒有遇到這樣的問題,最后還望大家給出更好的方案解決!

以上這篇Ant design vue中的聯(lián)動(dòng)選擇取消操作就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue.js項(xiàng)目打包上線的圖文教程

    vue.js項(xiàng)目打包上線的圖文教程

    下面小編就為大家分享一篇vue.js項(xiàng)目打包上線的圖文教程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2017-11-11
  • vue3+vite使用element-plus問題

    vue3+vite使用element-plus問題

    這篇文章主要介紹了vue3+vite使用element-plus問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • vue watch關(guān)于對(duì)象內(nèi)的屬性監(jiān)聽

    vue watch關(guān)于對(duì)象內(nèi)的屬性監(jiān)聽

    這篇文章主要介紹了vue watch關(guān)于對(duì)象內(nèi)的屬性監(jiān)聽的相關(guān)知識(shí),非常不錯(cuò),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下
    2019-04-04
  • vue3實(shí)現(xiàn)無縫滾動(dòng)列表效果(大屏數(shù)據(jù)輪播場景)

    vue3實(shí)現(xiàn)無縫滾動(dòng)列表效果(大屏數(shù)據(jù)輪播場景)

    vue3-scroll-seamless 是一個(gè)用于 Vue 3 的插件,用于實(shí)現(xiàn)無縫滾動(dòng)的組件,它可以讓內(nèi)容在水平或垂直方向上無縫滾動(dòng),適用于展示輪播圖、新聞滾動(dòng)、圖片展示等場景,本文就給大家介紹了vue3實(shí)現(xiàn)無縫滾動(dòng)列表效果,需要的朋友可以參考下
    2024-07-07
  • vue全局實(shí)現(xiàn)數(shù)字千位分隔符格式

    vue全局實(shí)現(xiàn)數(shù)字千位分隔符格式

    這篇文章主要為大家詳細(xì)介紹了vue全局實(shí)現(xiàn)數(shù)字千位分隔符格式,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • 基于Vue3.0開發(fā)輕量級(jí)手機(jī)端彈框組件V3Popup的場景分析

    基于Vue3.0開發(fā)輕量級(jí)手機(jī)端彈框組件V3Popup的場景分析

    這篇文章主要介紹了基于Vue3.0開發(fā)輕量級(jí)手機(jī)端彈框組件V3Popup,本文通過場景分析給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-12-12
  • element表格el-table實(shí)現(xiàn)虛擬滾動(dòng)解決卡頓問題

    element表格el-table實(shí)現(xiàn)虛擬滾動(dòng)解決卡頓問題

    當(dāng)頁面數(shù)據(jù)過多,前端渲染大量的DOM時(shí),會(huì)造成頁面卡死問題,本文主要介紹了element表格el-table實(shí)現(xiàn)虛擬滾動(dòng)解決卡頓問題,具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-10-10
  • vue 注冊組件的使用詳解

    vue 注冊組件的使用詳解

    Vue.js的組件的使用有3個(gè)步驟:創(chuàng)建組件構(gòu)造器、注冊組件和使用組件。這篇文章主要介紹了vue 注冊組件的使用,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2018-05-05
  • 如何用webpack4帶你實(shí)現(xiàn)一個(gè)vue的打包的項(xiàng)目

    如何用webpack4帶你實(shí)現(xiàn)一個(gè)vue的打包的項(xiàng)目

    這篇文章主要介紹了如何用webpack4帶你實(shí)現(xiàn)一個(gè)vue的打包的項(xiàng)目,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-06-06
  • 淺析Vue為什么需要同時(shí)使用Ref和Reactive

    淺析Vue為什么需要同時(shí)使用Ref和Reactive

    這篇文章主要想來和大家一起探討一下Vue為什么需要同時(shí)使用Ref和Reactive,文中的示例代碼簡潔易懂,感興趣的小伙伴可以跟隨小編一起了解一下
    2023-08-08

最新評(píng)論