vue switchコンポーネント


コンポーネント



	export default {
		props: {
		  value: {
			type: Boolean,
			default: true
		  },
		  event:'',
		  index:0,
		  item:{},
		  actionurl:''
		},
		data() {
		  return {
			me_checked: this.value,
			cc:this.value
		  }
		},
		watch: {
		  me_checked(val) {
			  let status = val*1
			 this.$emit(this.event, status,this.index);
		  }
		},
		methods: {
		  toggle(e) {
			  this.me_checked = !this.me_checked;
			  let status = this.me_checked
			  let id = this.item.zw_id
			  let g_status= status*1 
			  this.$api.request(this.actionurl,{id:id, status: g_status},'post').then((res)=>{
			  	uni.showToast({
			  		title:res.msg,
			  		icon:'none'
			  	})
				
			  }).catch((e)=>{
				 uni.showToast({
					title:e.msg,
					icon:'none'
				 })
				 let failstatus = false;
				 if(status== false){
					 failstatus=true
				 }else if(status==true){
					 failstatus=false
				 }
				 this.me_checked = failstatus
			  })
			  
		  }
		}
  }




よびだし
 


import myswitch from '../../components/switch'

statuschange:function(e,i){
    console.log(e)
 }