VUE DEMO之模擬登錄個(gè)人中心頁(yè)面之間數(shù)據(jù)傳值實(shí)例
lalala~ 先上代碼吧:
login.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>模擬登錄成功并跳轉(zhuǎn)頁(yè)面</title>
<script src='vue.js'></script>
<style>
.red{
color:red;
}
.ddd{
color:#333;
font-size: 13px;
}
</style>
</head>
<body>
<div id="app">
<h3 class="red">登錄</h3>
用戶名:<input type="text" v-model='userinfo.username' ><br>
密碼:<input type="password" v-model='userinfo.password' ><br>
<input type="submit" value="提交" @click='check'>
</div>
<script>
let vm = new Vue({
el:'#app',
data(){
return {
userinfo:{
username:'',
password:'',
}
}
},
methods:{
check(){
if(this.userinfo.username != '' && this.userinfo.password != ''){
alert('恭喜您,登錄成功');
//使用location 記錄用戶信息
if(!window.localStorage){
alert('您的瀏覽器不支持localStorage')
}else{
localStorage.setItem('userInfo',JSON.stringify(this.userinfo));
}
window.location.href='order.html'
}else{
alert('用戶名或者密碼不能為空')
}
}
}
})
</script>
</body>
</html>
order.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>模擬登錄成功并跳轉(zhuǎn)頁(yè)面</title>
<script src='vue.js'></script>
<style>
.red{
color:red;
}
.ddd{
color:#333;
font-size: 13px;
}
</style>
</head>
<body>
<div id="app">
<h3 class="red">個(gè)人中心</h3>
<div>
你好:<span class="ddd">{{username}}</span><br>
您的密碼是: <span class="ddd">{{password}}</span>
</div>
</div>
<script>
let vm = new Vue({
el:'#app',
data(){
return {
username:'',
password:''
}
},
mounted(){
if(!window.localStorage){
alert('瀏覽器不支持localStorage');
}else{
var data1 = localStorage.getItem('userInfo');
var data2 = JSON.parse(data1);
this.username = data2.username;
this.password = data2.password;
}
}
})
</script>
</body>
</html>
分析其中運(yùn)用的知識(shí)點(diǎn):
1. vue v-model 指令,把表單的值和data數(shù)據(jù)綁定,雙向數(shù)據(jù)綁定。
2. html5 window.localStorage 本地存儲(chǔ),用來(lái)存儲(chǔ)用戶信息(在實(shí)際項(xiàng)目中必須加密的,demo中沒(méi)有去做)。
3. JSON.parse() 將JSON字符串轉(zhuǎn)化成json格式
4. JSON.stringify() 將JSON轉(zhuǎn)化成json字符串
以上這篇VUE DEMO之模擬登錄個(gè)人中心頁(yè)面之間數(shù)據(jù)傳值實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue+element-ui 實(shí)現(xiàn)表格的分頁(yè)功能示例
這篇文章主要介紹了Vue+element-ui 實(shí)現(xiàn)表格的分頁(yè)功能示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-08-08
web前端vue實(shí)現(xiàn)插值文本和輸出原始html
這篇文章主要介紹了web前端vue實(shí)現(xiàn)插值文本和輸出原始html,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-01-01
vue3使用reactive包裹數(shù)組正確賦值問(wèn)題
這篇文章主要介紹了vue3使用reactive包裹數(shù)組正確賦值問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03
詳解Vue組件之間的數(shù)據(jù)通信實(shí)例
本篇文章主要介紹了詳解Vue組件之間的數(shù)據(jù)通信實(shí)例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-06-06
vueRouter--matcher之動(dòng)態(tài)增減路由方式
這篇文章主要介紹了vueRouter--matcher之動(dòng)態(tài)增減路由方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04
解決vue this.$forceUpdate() 處理頁(yè)面刷新問(wèn)題(v-for循環(huán)值刷新等)
這篇文章主要介紹了解決vue this.$forceUpdate() 處理頁(yè)面刷新問(wèn)題(v-for循環(huán)值刷新等),解決方法是使用this.$forceUpdate()強(qiáng)制刷新,文章給大家分享了代碼案例,需要的朋友參考下吧2018-07-07

