0👍
I would comment, but point restrictions. It seems like you’re only posting snippets of the code, so it’s hard to get a full picture. I assume that you’ve already set this.contract to be an Object? I don’t know what your data function looks like, and an error message would be helpful, but it sounds like you’re trying to assign a field on an object that doesn’t exist yet.
Edit
Thanks for the information. I’m not sure if your edit to b.vue was a mistake when you copied things over to stackoverflow, but based on the code you’ve provided, my guess is that you wrote data()
in the wrong place. You have it inside mounted()
, not as a key value of the component object, and thus this.contract
won’t access it.
I managed to get it working under the setup below
a.vue
import bus from './bus.js';
export default {
name: 'sitea',
methods: {
go(name) {
bus.$emit('setPartner', name);
}
}
}
b.vue
import bus from './bus.js'
export default {
name: 'siteb',
data() {
return {
contract: {
contractSubject: ''
}
}
},
mounted() {
bus.$once('setPartner', data => {
console.log(data);
this.contract.contractSubject = data;
});
}
}