In Vue.js, I have a data variable roomFilters which has an array and i want to assign that array to key -> items in filter1 object, but my code is not working. I am getting the array in roomFilters state variable but how to use it inside object?
<script>
import { mapState, mapActions } from 'vuex';
import ns from '@/vue/store/namespaces';
export default {
data() {
return {
filterData: {
filter1: {
key: 'filter1',
title: 'Space Attributes',
criteriaType: 'Multivalue',
items: this.roomFilters,
itemsToShow: 2
},
}
};
},
computed: {
...mapState(ns.global, ['roomFilters'])
},
created() {
this.fetchRoomFilters();
},
methods: {
...mapActions(ns.global, ['fetchRoomFilters']),
}
}
};
</script>
Since your property is based on other one it should be defined as a computed one :
export default {
data() {
return {
};
},
computed: {
...mapState(ns.global, ['roomFilters']),
filterData(){
return {
filter1: {
key: 'filter1',
title: 'Space Attributes',
criteriaType: 'Multivalue',
items: this.roomFilters,
itemsToShow: 2
},
}
}
},
created() {
this.fetchRoomFilters();
},
methods: {
...mapActions(ns.global, ['fetchRoomFilters']),
}
}
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.