export default {
data() {
return {
myVars: {
a: 1,
b: "some",
c: [1, 2, 3],
},
data: ['a', 'b', 'c'],
}
}
}
<div v-for="(elem, key) in data" :="key">{{ myVars[elem] }}</div>
export default {
data() {
return {
a: 1,
b: "some",
c: [1, 2, 3],
data: ['a', 'b', 'c'],
}
},
methods: {
getDataValue(param) {
return this[param] || null;
},
},
}
<div v-for="(elem, key) in data" :="key">{{ getDataValue(elem) }}</div>
<component-one v-on:click-some-button="hideBlockkInOtherComponent"></component-one>
<component-two ref="othercomponent"></component-two>
methods: {
hideBlockkInOtherComponent () {
this.$refs.othercomponent.hideBlock();
}
}
<div><button v-on:click="sendClickForParent">click</button></div>
methods: {
sendClickForParent () {
this.$emit('click-some-button');
}
}
<div>
<div v-if="showBlock">my block</div>
</div>
data () {
return {
showBlock: true,
};
},
methods: {
hideBlock () {
this.showBlock = false;
}
}
this.array.splice(oldElementIndex, 1, newElement)
this.$set(this.array, oldElementIndex, newElement)
this.array = this.array.map(el => {
el.someParam = 1
return el
})
async getAllUsers() {
const { data: users } = await axios.get('http://jsonplaceholder.typicode.com/users')
this.posts = this.posts.map(p => {
p.author = users.find(u => u.id === p.userId)
return p
})
},
data()
data: () => ({ param: 1 }) //Возвращает объект
data: () => {
return {
param: 1
}
}
this.inputs.forEach((value, index) => {
this.$set(this.inputs, index, {...value, label: value.label1})
});
this.inputs = this.inputs.map(item => ({ ...item, label: item.label1 }))