vue+element ui 实现右侧穿梭框上下排序

子组件:

<template>
	<div>
		<el-row>
			<el-col :span="20">
				<el-transfer v-model="outputListTemp" :data="inputList" :props="alias" target-order="push" @right-check-change="rightCheck"></el-transfer>
			</el-col>
			<el-col :span="4" style="margin-top: 95px;">
				<div style="margin-bottom: 10px;">
					<el-button icon="el-icon-arrow-up" circle :disabled="upDownDisable" @click="upData"></el-button>
				</div>
				<div>
					<el-button icon="el-icon-arrow-down" circle :disabled="upDownDisable" @click="downData"></el-button>
				</div>
			</el-col>
		</el-row>
	</div>
</template>

<script>
	import {
		Message,
		Notification
	} from 'element-ui';
	export default {
		name: 'myTransfer',
		props: [
			'value',
			'inputList',
			'alias'
			],
		data() {
			return {
				upDownDisable:true,
				tempSelectionKeys:[],
				outputListTemp:[]
			}
		},
		watch: {
			value(val) {
				this.outputListTemp = val;
			},
			outputListTemp(val){
				this.$emit('input', val);
			}
		},
		mounted() {
			
		},
		methods: {
            rightCheck(selectionKeys, changeKeys){
            	this.tempSelectionKeys = selectionKeys;
            	if(selectionKeys.length > 0){
            		this.upDownDisable = false;
            	}else{
            		this.upDownDisable = true;
            	}
            },
            upData(){
				if(this.tempSelectionKeys.length > 1){
					this.$message({
						type: 'warning',
						message: '仅支持单选调顺序'
					});
					return ;
				}
            	let indexNum = 0;
            	for(let i=0; i<this.tempSelectionKeys.length; i++){
            		indexNum = this.outputListTemp.indexOf(this.tempSelectionKeys[i])
            		if(indexNum > 0){
            			this.outputListTemp.splice(indexNum - 1, 0, this.tempSelectionKeys[i]);
            			this.outputListTemp.splice(indexNum + 1, 1);
            		}
            	}
            },
            downData(){
				if(this.tempSelectionKeys.length > 1){
					this.$message({
						type: 'warning',
						message: '仅支持单选调顺序'
					});
					return ;
				}
            	let indexNum = 0;
            	for(let i=0; i<this.tempSelectionKeys.length; i++){
            		indexNum = this.outputListTemp.indexOf(this.tempSelectionKeys[i]);
            		if(indexNum > -1 && indexNum != this.outputListTemp.length - 1){
            			this.outputListTemp.splice(indexNum + 2, 0, this.tempSelectionKeys[i]);
            			this.outputListTemp.splice(indexNum, 1);
            		}
            	}
            }
		}
	}
</script>
<style type="text/css">
</style>

父组件调用:

<el-dialog title="提示" :visible.sync="dialogVisible" width="35%">
	<my-transfer v-model="chapterNameIdList" :inputList="chapterNameList" :alias="{key: 'id',label: 'templateChapterName'}"></my-transfer>
	<span slot="footer" class="dialog-footer">
		<el-button @click="dialogVisible = false">取 消</el-button>
		<el-button type="primary" @click="jumpPage('merge','','')">确 定</el-button>
	</span>
</el-dialog>

 

<script>
	import myTransfer from './myTransfer.vue';
</script>

效果图:

 

 

  • 8
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
可以使用 Element UI 中的 Input 组件和 Autocomplete 组件来实现搜索功能。 首先,需要在页面中引入 Element UI 库和 Vue.js 库: ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Vue + Element UI Search Box</title> <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"> </head> <body> <div id="app"> <el-autocomplete v-model="keyword" :fetch-suggestions="querySearchAsync" placeholder="请输入搜索关键字"> <el-button slot="append" icon="el-icon-search" @click="search">搜索</el-button> </el-autocomplete> </div> <script src="https://unpkg.com/vue/dist/vue.js"></script> <script src="https://unpkg.com/element-ui/lib/index.js"></script> <script> new Vue({ el: '#app', data() { return { keyword: '', suggestions: [] }; }, methods: { querySearchAsync(queryString, cb) { // 在这里实现异步搜索逻辑,返回搜索结果数组 }, search() { // 在这里实现搜索操作 } } }); </script> </body> </html> ``` 然后,在 Vue 实例中定义一个 data 对象来保存搜索关键字和搜索结果,以及两个方法来实现搜索功能: - querySearchAsync:调用异步方法进行搜索,返回搜索结果数组给 Autocomplete 组件。 - search:根据搜索关键字进行具体的搜索操作。 接下来,需要在 querySearchAsync 方法中实现异步搜索逻辑,可以使用 Ajax 或者 Fetch API 发送异步请求获取搜索结果。搜索结果数组的格式需要符合 Autocomplete 组件的要求,即每个元素都是一个对象,包含 value 和 label 两个属性,分别表示搜索结果的值和显示文本。 ```javascript methods: { querySearchAsync(queryString, cb) { axios.get('/api/search', { params: { q: queryString } }).then(response => { const data = response.data; const suggestions = data.map(item => { return { value: item.id, label: item.name }; }); cb(suggestions); }).catch(error => { console.error(error); }); }, search() { // 根据 this.keyword 进行具体的搜索操作 } } ``` 以上代码使用 axios 库发送异步请求,返回的数据是一个包含多个对象的数组,每个对象包含 id 和 name 两个属性。在 querySearchAsync 方法中将数组转换成 Autocomplete 组件需要的格式,并调用 cb 方法将搜索结果返回给 Autocomplete 组件。 最后,在 search 方法中可以根据 this.keyword 属性进行具体的搜索操作,例如跳转到搜索结果页面、展示搜索结果列表等。 完成以上步骤后,就可以实现一个基于 Vue.js 和 Element UI 的纯前端搜索

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值