Login-Komponente
Bus importieren von „@/components/eventBus“
Standard exportieren {
Name: 'login',
Daten () {
return {
navcard:['首页','工作室简介','人员分工','项目计划','重点故障分析','技能创新','带徒传技','技能培训','技术交流论坛'],
username:'',
userpassword:'',
loginstate:'3'
}
},
methods:{
login:function(){
this.$http.get("http://localhost/web/njndc1/api.php",{params:{
'username':this.username,'userpassword':this.userpassword,'action':'login'
}}).then(
function (res) {
// 处理成功的结果
this.loginstate=res.body;
console.log(this.loginstate)
if(res.body==1){
var self=this;
this.$router.push('/mainpage')
bus.$emit("login_loginstae",'success')
}else{
bus.$emit("login_loginstae",'failed')
}
},function (res) {
// 处理失败的结果
alert('程序错误')
}
);
}
}
}
</script>
Hauptseitenkomponente
<script>
Bus importieren von „@/components/eventBus“
Standard exportieren {
Name: 'login',
Daten () {
return {
navcard:['首页','工作室简介','人员分工','项目计划','重点故障分析','技能创新','带徒传技','技能培训','技术交流论坛'],
username:'',
userpassword:'',
msg:''
}
},
methods:{
},
erstellt(){
var self=this;
bus.$on("login_loginstate",function(msg){
console.log(msg)
self.msg=msg
}
)
}
}
</script>
已解决,我原来的文件目录把eventBus放到了src/components,且文件名是.vue,后来直接放到assets/下面文件名改为.js后得到了解决