there is this vue.js page which opens a child window one using following line;
this.presentation = window.open(
this.$router.resolve({name:’presentation’}).href,
‘child window’,
‘width=auto,height=auto’
);
This works like a charm, but now I need to call it’s methods.
I tried to accessing them like so.
Parent:
this.presentation.setPage(0);
Child:
export default {
name: ‘Presentation’,
data() {
return {
page: null
}
},
methods: {
setPage(_page) {
this.page = _page;
}
}
This throws following error.
TypeError: “this.presentation.setPage is not a function”
Why can’t I call child methods? How can I fix this?
Solution :
First, from the window.open() documentation:
windowName
… The name should not contain whitespace. …
Return value:
A Window object representing to the newly created window.
the this.presentation contains Window object, not the vue.js object. Of course, it doesn’t have setPage() method.
Perhaps, something like that could work (in the child component):
{
mounted() {
window.setPage = (page) => this.setPage(page);
}
}