vue组件使用store仓库

第一步:

数据和方法
 this.repeatData = res.data.data.data;
  this.setIsShowRepeatList(true);

第二步:

在methods方法中定义方法
...mapMutations([
          'setIsShowRepeatList',
        ]),
        

第三步:

初始化组件
import RepeatListDialog from '../../components/repeatListDialog'
 components:{
      RepeatListDialog
    },
 <RepeatListDialog :repeatData="repeatData"/>
 第四步:
 

在store仓库index.js页面的mutations中设置isShowRepeatList变量
state: {
moduleName: ‘claim’,
routes: null,
menu: [],
sysMenu: null, // 系统权限菜单
userInfo: Vue.prototype.$cookies.get(‘userInfo’),
isShowRepeatList:false,

},
setIsShowRepeatList(state, data){
state.isShowRepeatList=data;
}


组件
<template>
	<div v-if="isShowRepeatList">
		<el-dialog
			title="提示"
			:visible.sync="isShowRepeatList"
			 width="26%"
			:before-close="closeDialog"
		>
			<span class="repeat-list-tip">未重复数据已导入,以下审批编号对应的数据为重复数据,请确认!</span>
			<ul class="repeat-list">
				<li v-for="(item, index) in repeatData" :key="index">{{ item }}</li>
			</ul>
			<span slot="footer" class="dialog-footer">
				<el-button type="primary" @click="closeDialog">确认</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
import { mapMutations, mapState } from 'vuex'
export default {
	name: 'repeatListDialog',
	data() {
		return {}
	},
	props: [
		'repeatData', // 重复数据列表
	],
	computed: {
		...mapState([
			'isShowRepeatList',
		]),
	},
	methods: {
		...mapMutations([
			'setIsShowRepeatList',
		]),
		closeDialog() {
			this.setIsShowRepeatList(false)
		},
	},
}
</script>

<style lang="scss" scoped>
.repeat-list-tip {
	line-height: 20px;
	font-weight: bold;
}
.repeat-list {
	margin-top: 10px;
	height: 300px;
	border: 1px solid #ccc;
	overflow-y: scroll;
	li {
		margin: 5px;
	}
}
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值