组件-Element—Transfer(穿梭框)
作者:互联网
组件-Element—Transfer(穿梭框)
组件—穿梭框
-
基础用法
<template> <el-transfer v-model="value" :data="data"></el-transfer> </template> <script> export default { data() { const generateData = _ => { const data = []; for (let i = 1; i <= 15; i++) { data.push({ key: i, label: `备选项 ${ i }`, disabled: i % 4 === 0 }); } return data; }; return { data: generateData(), value: [1, 4] }; } }; </script>
-
可搜索
<template> <el-transfer filterable :filter-method="filterMethod" filter-placeholder="请输入城市拼音" v-model="value" :data="data"> </el-transfer> </template> <script> export default { data() { const generateData = _ => { const data = []; const cities = ['上海', '北京', '广州', '深圳', '南京', '西安', '成都']; const pinyin = ['shanghai', 'beijing', 'guangzhou', 'shenzhen', 'nanjing', 'xian', 'chengdu']; cities.forEach((city, index) => { data.push({ label: city, key: index, pinyin: pinyin[index] }); }); return data; }; return { data: generateData(), value: [], filterMethod(query, item) { return item.pinyin.indexOf(query) > -1; } }; } }; </script>
-
可自定义
<template> <p style="text-align: center; margin: 0 0 20px">使用 render-content 自定义数据项</p> <div style="text-align: center"> <el-transfer style="text-align: left; display: inline-block" v-model="value" filterable :left-default-checked="[2, 3]" :right-default-checked="[1]" :render-content="renderFunc" :titles="['Source', 'Target']" :button-texts="['到左边', '到右边']" :format="{ noChecked: '${total}', hasChecked: '${checked}/${total}' }" @change="handleChange" :data="data"> <el-button class="transfer-footer" slot="left-footer" size="small">操作</el-button> <el-button class="transfer-footer" slot="right-footer" size="small">操作</el-button> </el-transfer> </div> <p style="text-align: center; margin: 50px 0 20px">使用 scoped-slot 自定义数据项</p> <div style="text-align: center"> <el-transfer style="text-align: left; display: inline-block" v-model="value4" filterable :left-default-checked="[2, 3]" :right-default-checked="[1]" :titles="['Source', 'Target']" :button-texts="['到左边', '到右边']" :format="{ noChecked: '${total}', hasChecked: '${checked}/${total}' }" @change="handleChange" :data="data"> <span slot-scope="{ option }">{{ option.key }} - {{ option.label }}</span> <el-button class="transfer-footer" slot="left-footer" size="small">操作</el-button> <el-button class="transfer-footer" slot="right-footer" size="small">操作</el-button> </el-transfer> </div> </template> <style> .transfer-footer { margin-left: 20px; padding: 6px 5px; } </style> <script> export default { data() { const generateData = _ => { const data = []; for (let i = 1; i <= 15; i++) { data.push({ key: i, label: `备选项 ${ i }`, disabled: i % 4 === 0 }); } return data; }; return { data: generateData(), value: [1], value4: [1], renderFunc(h, option) { return <span>{ option.key } - { option.label }</span>; } }; }, methods: { handleChange(value, direction, movedKeys) { console.log(value, direction, movedKeys); } } }; </script>
-
数据项属性别名
<template> <el-transfer v-model="value" :props="{ key: 'value', label: 'desc' }" :data="data"> </el-transfer> </template> <script> export default { data() { const generateData = _ => { const data = []; for (let i = 1; i <= 15; i++) { data.push({ value: i, desc: `备选项 ${ i }`, disabled: i % 4 === 0 }); } return data; }; return { data: generateData(), value: [] }; } }; </script>
-
Attributes
-
Slot
-
Scoped Slot
-
Methods
-
Events
标签:generateData,const,option,Transfer,Element,export,pinyin,组件,data 来源: https://blog.csdn.net/GU_AO_SHI_TAI_DU/article/details/94564609