我在子组件中有数据props .在挂载功能的子组件内部,我需要从props 中获取特定值,并设置 Select 下拉值.我正在使用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和Update函数中,但每次值发生变化时都会调用这个函数,这不是必需的.我只需要第一次更改它,就可以设置下拉初始值.