登入元件
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('程序错误')
}
);
}
}
}
</script>
主頁元件
<script>
import bus from "@/components/eventBus"
export default {
name: 'login',
data () {
return {
navcard:['首页','工作室简介','人员分工','项目计划','重点故障分析','技能创新','带徒传技','技能培训','技术交流论坛'],
username:'',
userpassword:'',
msg:''
}
},
methods:{
},
created(){
var self=this;
bus.$on("login_loginstate",function(msg){
console.log(msg)
self.msg=msg
}
)
}
}
</script>
我想大声告诉你2017-05-16 13:33:37
已解決,我原來的文件目錄把eventBus放到了src/components,且文件名是.vue,後來直接放到assets/下面文件名改為.js後得到了解決