I have a Vue instance called appDetails. This instance belongs to app.html. In it I declared function getApp, which returns the name of app:
var appDetails = new Vue({
el: '#appDetails',
methods: {
getApp() {
var path = url;
var formData = "id=" + id;
return axios.get(path, formData)
.then((res) => {
return res.data.name;
})
}})
Then in another js file I created product instance. This js file belongs to product.html. In it I declared computed property. In body of property I want to call a function of appDetails Vue instance. The returned data of the property is the name of app.
var product = new Vue({
el: '#product',
computed : {
app_name: function() {
appDetails.getApp()
.then((returnVal) => {
return returnVal;
})
}});
In product.html I wrote:
<a>{{app_name}}</a>
But when I load page, there is no text. tag is empty.
But when I tried to console log it showed me a name. Anybody knows how to solve this problem?
product? Do you get a vue instance?$parentto call methods on the parent component or$refsto access child components, but the bigger issue is your computed property. The function must not be asynchronous.{{product.app_name}}