【发布时间】:2017-12-29 14:56:25
【问题描述】:
我在子组件中有数据道具。在挂载函数的子组件内部,我需要从道具中获取特定值并设置选择下拉值。我正在使用运行良好的 vue-multiselect 插件。这是代码。
module.exports = {
props: ["Subscriptions"]
mounted: function () {
let vm = this;
Vue.nextTick(function () {
// I want to access props here but it return 0 length array
console.log(vm.$parent.Subscriptions);
});
},
beforeUpdate() {
let vm = this;
console.log(vm.$parent.Subscriptions);
},
// updated() {
// let vm = this;
// console.log(vm.$parent.Subscriptions);
// }
};
现在我只有在 beforeUpdate 和 updated 函数中获得订阅,但每次值发生不需要的变化时都会调用它。我只需要第一次更改它即可设置下拉初始值。
【问题讨论】:
标签: vue.js vuejs2 vue-component