Login component
import bus from "@/components/eventBus"
export default {
name: 'login',
data () {
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('程序错误') } ); }
}
}
Main page component
Solved. My original file directory put eventBus in src/components, and the file name was .vue. Later, I put it directly under assets/ and changed the file name to .js. The problem was solved