How to mutating prop in Nuxt or Vuejs
Mutating prop in Nuxt
To be able mutating prop in Nuxt 3 or Vuejs , we need to hold the value in a ref .
<script lang="ts" setup>
const props = defineProps({
data: {
type: Object,
required: true
},
});
// setup a new ref
const content = ref(props.data);
// we now can do mutation through content, ie:
// since data prop is an Object
content.value = {title: 'some new title'}
// if data is an Array
content.value[0] = {title: 'some new title'};
// if data is a String
content.value = 'some new string';
</script>