vue2/3自定义组件支持v-model的方式区别

avatar
作者
猴君
阅读量:0

vue2

fireTicketEdit.vue

<baseInfo :ticket.sync="ticketForm" /> 

baseInfo.vue

<script> export default {   props: {     ticket: Object   },   computed: {     ticketForm: {       get() {         return this.ticket       },       set(newValue) {         this.$emit('update:ticket', newValue)       }     }   },   methods: {     deleteWorkOrder() {       this.ticketForm.workOrderId = null     }   } } </script> 

vue3

fireTicketEdit.vue

<baseInfo v-model:ticket="ticketForm" /> 

baseInfo.vue

<script setup> import { computed, emit } from 'vue'  const props = defineProps({   ticket: Object })  const ticketForm = computed({   get() {     return props.ticket   },   set(newValue) {     emit('update:ticket', newValue)   } })  function deleteWorkOrder() {   ticketForm.value.workOrderId = null } </script> 

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!