activeCategory: (state, {activeCategoryId}) => {
return state.all.find( (p) => p.id === activeCategoryId) || null
}
activeCategory: (state) => {
return state.all.find( (p) => p.id === state.activeCategoryId) || null
}
data() {
return {
unwatcher: null
}
},
...
methods: {
onDevgroupClick(item) {
// Clone device object(for editing)
if (this.unwatcher) {
this.unwatcher()
}
this.selectedDevice = Object.assign({}, item);
this.hasChanges = false;
this.$nextTick(() => {
this.unwatcher = this.$watch('selectedDevice', this.hasChanged, { deep: true })
})
},
hasChanged() {
this.hasChanges = true;
}
}
// mixin setLocation.js
export default {
created() {
this.$store.currentLocation = this.name
}
}
// ... in some component
import locationMixin from 'path-to-mixins/setLocation'
export default {
mixins: [locationMixin],
...
components: {Example}
есть components: {Example: Example}
<div id="example"><example></example></div>
2. Пример кода