Vue實(shí)現(xiàn)注冊(cè)頁面的用戶交互詳解
Vue代碼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>用戶注冊(cè)</title>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<style>
.container {
margin:0 auto;
margin-top: 70px;
text-align: center;
width: 300px;
}
.subTitle {
color:gray;
font-size: 14px;
}
.title {
font-size: 45px;
}
.input {
width: 90%;
}
.inputContainer {
text-align: left;
margin-bottom: 20px;
}
.subContainer {
text-align: left;
}
.field {
font-size: 14px;
}
.input {
border-radius: 6px;
height: 25px;
margin-top: 10px;
border-color: silver;
border-style: solid;
background-color: cornsilk;
}
.tip {
margin-top: 5px;
font-size: 12px;
color: gray;
}
.setting {
font-size: 9px;
color: black;
}
.label {
font-size: 12px;
margin-left: 5px;
height: 20px;
vertical-align:middle;
}
.checkbox {
height: 20px;
vertical-align:middle;
}
.btn {
border-radius: 10px;
height: 40px;
width: 300px;
margin-top: 30px;
background-color: deepskyblue;
border-color: blue;
color: white;
}
</style>
</head>
<body>
<div class="container" id="Application">
<div class="container">
<div class="subTitle">加入我們,一起創(chuàng)造美好世界</div>
<h1 class="title">創(chuàng)建你的賬號(hào)</h1>
<div v-for="(item, index) in fields" class="inputContainer">
<div class="field">{{item.title}}
<span v-if="item.required" style="color: red;">*</span></div>
<input v-model="item.model" class="input" :type="item.type" />
<div class="tip" v-if="index == 2">請(qǐng)確認(rèn)密碼程度需要大于6位</div>
</div>
<div class="subContainer">
<div class="setting">偏好設(shè)置</div>
<input v-model="receiveMsg" class="checkbox" type="checkbox" /><label class="label">接收更新郵件</label>
</div>
<button @click="createAccount" class="btn">創(chuàng)建賬號(hào)</button>
</div>
</div>
<script>
const App = {
data(){
return{
fields:[
{
title:'用戶名',
required:true,
type:'text',
model:''//與輸入框雙向綁定的數(shù)據(jù)
},
{
title:'郵箱地址',
required:false,
type:'text',
model:''//與輸入框雙向綁定的數(shù)據(jù)
},{
title:'密碼',
required:true,
type:'password',
model:''//與輸入框雙向綁定的數(shù)據(jù)
}
],
receiveMsg:false
}
},
computed:{
//定義"賬號(hào)"計(jì)算屬性,獲取值與設(shè)置值時(shí)同步映射到data中具體的存儲(chǔ)屬性
name:{
get(){
return this.fields[0].model
},
set(value){
this.fields[0].model = value
}
},
//定義"郵箱"計(jì)算屬性,獲取值與設(shè)置值時(shí)同步映射到data中具體的存儲(chǔ)屬性
email:{
get(){
return this.fields[1].model
},
set(value){
this.fields[1].model = value
}
},
password:{
get(){
return this.fields[2].model
},
set(value){
this.fields[2].model = value
}
},
},
methods:{
//檢查郵箱格式是否正確
emailCheck(){
var verify = /^\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/;
if(!verify.test(this.email)){
return false
}else{
return true
}
},
//模擬業(yè)務(wù)上的注冊(cè)操作
createAccount(){
if(this.name.length == 0){
alert('請(qǐng)輸入用戶名')
return
}else if(this.password.length <= 6){
alert('密碼設(shè)置需要大于6位字符')
return
}else if(this.email.length > 0 && !this.emailCheck(this.email)){
alert('請(qǐng)輸入正確的郵箱')
return
}
alert('注冊(cè)成功')
console.log(`name:${this.name}\npassword:${this.password}\nemail:${this.email}\nreceiveMsg:${this.receiveMsg}`)
}
}
}
Vue.createApp(App).mount("#Application")
</script>
</body>
</html>
實(shí)現(xiàn)效果

控制臺(tái)上打印注冊(cè)信息

到此這篇關(guān)于Vue實(shí)現(xiàn)注冊(cè)頁面的用戶交互詳解的文章就介紹到這了,更多相關(guān)Vue注冊(cè)頁面用戶交互內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
使用Vue完成一個(gè)簡(jiǎn)單的todolist的方法
本篇文章主要介紹了使用Vue完成一個(gè)簡(jiǎn)單的todolist的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-12-12
vuex中...mapstate和...mapgetters的區(qū)別及說明
這篇文章主要介紹了vuex中...mapstate和...mapgetters的區(qū)別及說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08
富文本編輯器quill.js開發(fā)之自定義格式擴(kuò)展
這篇文章主要為大家介紹了富文本編輯器quill.js開發(fā)之自定義格式擴(kuò)展,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08
vue 組件數(shù)據(jù)加載解析順序的詳細(xì)代碼
Vue.js的解析順序可以概括為:模板編譯、組件創(chuàng)建、數(shù)據(jù)渲染、事件處理和生命周期鉤子函數(shù)執(zhí)行,接下來通過本文給大家介紹vue 組件數(shù)據(jù)加載解析順序的完整代碼,感興趣的朋友跟隨小編一起看看吧2024-03-03
Vue.js路由實(shí)現(xiàn)選項(xiàng)卡簡(jiǎn)單實(shí)例
這篇文章主要為大家詳細(xì)介紹了Vue.js路由實(shí)現(xiàn)選項(xiàng)卡簡(jiǎn)單實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-07-07
Vue?監(jiān)聽視頻播放時(shí)長(zhǎng)的實(shí)例代碼
本文介紹了如何通過源碼實(shí)現(xiàn)對(duì)視頻實(shí)時(shí)時(shí)長(zhǎng)、播放時(shí)長(zhǎng)和暫停時(shí)長(zhǎng)的監(jiān)聽,詳細(xì)闡述了相關(guān)技術(shù)的應(yīng)用方法,幫助開發(fā)者更好地掌握視頻監(jiān)控技術(shù),提高用戶體驗(yàn)2024-10-10
解決vue 更改計(jì)算屬性后select選中值不更改的問題
下面小編就為大家分享一篇解決vue 更改計(jì)算屬性后select選中值不更改的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-03-03
淺談vue 組件中的setInterval方法和window的不同
這篇文章主要介紹了淺談vue 組件中的setInterval方法和window的不同,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-07-07
在vue中給后臺(tái)接口傳的值為數(shù)組的格式代碼
這篇文章主要介紹了在vue中給后臺(tái)接口傳的值為數(shù)組的格式代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-11-11
element的表單校驗(yàn)證件號(hào)規(guī)則及輸入“無”的情況校驗(yàn)通過(示例代碼)
這篇文章主要介紹了element的表單校驗(yàn)證件號(hào)規(guī)則及輸入“無”的情況校驗(yàn)通過,使用方法對(duì)校驗(yàn)數(shù)據(jù)進(jìn)行過濾判斷,本文通過示例代碼給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧2023-11-11

