为了处理bootstrapVue的问题,也是花了一点时间处理,不过好在,慢慢地熟悉Vue和bootstrapVue的写法,可以真的开始做登入功能了,不过注册功能,暂时不太确定社区网站,是否需要提供注册功能,就先不开发这件事!
跟教学不同的是,我们是使用Json Server,所以就先启动
json-server db.json
可以看到我们的资料後端服务起来了
我们要呼叫的是http://localhost:3000/householder
新增提示工具SweetAlert
npm install sweetalert2
import Swal from 'sweetalert2';
window.Swal = Swal;
<input type="email" v-model="email" class="form-control" id="email" aria-describedby="emailHelp" placeholder="Enter Account">
...省略
<button class="btn btn-primary" @click="login">Login</button>
script内容建置
<script>
import global from '../Global.vue';
import axios from'axios'
export default {
name: 'Login',
props: {
msg: String
},
data() {
return {
email:null,
password:null,
db_api:global.db_api
}},
methods:{
async login(){
//登入方法
console.log(`${this.db_api}`+"householder/?loginId=D07-1&loginPass=d071")
let result = await axios.get(`${this.db_api}`+"householder?loginId="+`${this.email}`+"&loginPass="+`${this.password}`)
if(result.status==200 && result.data.length==1 ){
sessionStorage.setItem("user-info",JSON.stringify(result.data[0]))
let user=sessionStorage.getItem('user-info')
Swal.fire({
position: 'top',
icon: 'success',
title: '登入成功!!',
showConfirmButton: false,
timer: 1500
}).then(() => {
this.$refs['login'].hide()
window.location.reload()
});
}
else{
// 密码错误提醒
Swal.fire({
position: 'top',
icon: 'error',
title: 'Wrong account or password.',
showConfirmButton: false,
timer: 5000
});
}
}
}
</script>
<script>
const db_api=" http://localhost:3000/"
export default {
db_api,
}
</script>
跟范例网站的内容比较,因为後端的内容不同,写法就会有差异,这边就呈现我调整过後的样子!!
透过调整也可以学到更多,了解差异,就让我们继续下去吧~
<<: Day20 - Fabricjs 与 Image map 仿制 highlight 场地图 说明
领导者不创造跟随者,他们只是创造更多领导者。 Leaders don't create follow...
今天要来介绍如何从 NiFi 将 FlowFiles 送到 SNS 和 SQS,一样就有原生的 Pr...
Ubuntu - Ubuntu 查看 CPU 温度 参考资料 网址如下: How to Get CP...
展开运算子及 其余运算子( 又称 其余参数 ) 他们有共通特点,那就是「 都跟阵列有关 」 写法...
本文内容 接续,Day27 的内容,纪录阅读有关 Angular Route 的 pathMatch...