我正在尝试使用安装在drawercontent.vue中的函数来调用该函数,但是它不起作用。
我尝试了诸如创建函数之类的常规方法,并在页面加载时调用了该方法。
我上传了完整的代码,是为了易于理解。
import Home from "./Home";
import Browse from "./Browse";
import Featured from "./Featured";
import Search from "./Search";
import Login from "./Login";
import Settings from "./Settings";
import * as utils from "~/shared/utils";
import SelectedPageService from "~/shared/selected-page-service";
import * as appSettings from "tns-core-modules/application-settings";
let methods = {
onNavigationItemTap: (component) => {
this.$navigateTo(component, {
clearHistory: true
});
utils.closeDrawer();
},
feedData: () => {
obj.userName = appSettings.getString("user_display_name")
obj.userEmail = appSettings.getString("user_email")
alert("data feeded")
},
logoutUser: () => {
appSettings.clear();
appSettings.remove("user_display_name");
appSettings.remove("user_email");
if(appSettings.getString("user_email") == null || appSettings.getString("user_email") == ''){
alert("user email id removed");
}
if(appSettings.getString("user_display_name") == null || appSettings.getString("user_display_name") == ''){
alert("user name removed");
}
utils.closeDrawer();
this.$navigateTo(Login, {
clearHistory: true
});
}
}
let obj = {
mounted: () => {
SelectedPageService.getInstance().selectedPage$
.subscribe((selectedPage) => this.selectedPage = selectedPage);
methods.feedData();
alert("data Feeded");
},
data: () => {
return {
Home: Home,
Browse: Browse,
Featured: Featured,
Search: Search,
Login: Login,
Settings: Settings,
selectedPage: "",
userName:"",
userEmail:""
};
},
components: {
Home,
Browse,
Featured,
Search,
Login,
Settings
},
methods
}
export default {
methods,
obj
}
</script>
feeddata没有调用,我设置了警报来检查但没有成功。
答案 0 :(得分:0)
好,所以您必须将方法的声明移到顶部,然后您可以在方法内部调用feedData
let methods = {
onNavigationItemTap: (component) => {
this.$navigateTo(component, {
clearHistory: true
});
utils.closeDrawer();
},
feedData: () => {
this.userName = appSettings.getString("user_display_name");
this.userEmail = appSettings.getString("user_email");
}
};
let obj = {
mounted: () => {
SelectedPageService.getInstance().selectedPage$
.subscribe((selectedPage) => this.selectedPage = selectedPage);
methods.feedData();
alert("datta Feeded");
},
data: () => {
return {
userName: "",
userEmail: ""
};
},
methods
};
export default {
methods,
obj
}