亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue組件表單數(shù)據(jù)回顯驗證及提交的實例代碼

 更新時間:2018年08月30日 08:48:59   作者:codingNoob  
今天小編就為大家分享一篇vue組件表單數(shù)據(jù)回顯驗證及提交的實例代碼,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

最近項目需要到vue開發(fā)單頁面,所以就研究一下表單數(shù)據(jù)的回顯,驗證及提交如何用vue組件的方式實現(xiàn)。

代碼如下:

<template>
 <div class="index">
 <!--header-bar></header-bar-->
 <div style="margin:20px;">
 <div class="item">
 <p>住戶名稱:</p>
 <p>
  <input type="text" value="username" v-model="formStatus.username" placeholder="輸入名稱">
 </p>
 </div>
 <div class="item">
 <p>住戶類型:</p>
 <p>
  <label v-for="(item, index) in zhuhuType">
  <span>{{item.name}}</span>
  <input type="radio" name = "zhuhutype" :value="item.id" :checked="item.isChecked" @click="changeZh(index)" v-model="formStatus.zhuhuType">
  </label>
 </p>
 </div>
 <div class="item">
 <p>設備名稱:</p>
 <p>
  <label v-for="(item, index) in shebeiType">
  <span>{{item.name}}</span>
  <input type="checkbox" :value="item.id" :checked="item.isChecked" @click="changeSb(index)" v-model="formStatus.shebeiType">
  </label>
 </p>
 </div>
 <div class="item">
 <p>住戶大小:</p>
 <p>
  <select v-model="formStatus.zhuhudaxiao">
  <option value="0">請選擇</option>
  <option v-for="option in zhuhudaxiao" v-model="zhuhudaxiao" :id = "option.id" :value="option.value" >{{option.name}}</option>
  </select>
 </p>
 </div>
 <div class="item">
 <p>住戶留言:</p>
 <p>
  <textarea value="userword" v-model="formStatus.userword"></textarea>
 </p>
 </div>

 </div>
 <p style="margin:20px 0;"><button @click="save">點擊保存</button></p>
 </div>
</template>
<script>
 import Vue from 'vue'
 import axios from 'axios';
 import ElementUI from 'element-ui'
 import URL from '../utils/Tools/URL.js'
 import 'element-ui/lib/theme-chalk/index.css'
 Vue.use(ElementUI)
 import headerBar from '../modules/headerBar.vue';
 export default {
 name: 'index',
 data (){
 return {
 zhuhuType: [],
 shebeiType: [],
 zhuhudaxiao: [],
 //綁定改變后的表單值用于提交
 formStatus: {
  username: "",
  zhuhuType: 43,
  shebeiType: [52, 23],
  zhuhudaxiao: "",
  userword: ""
 }
 }
 },
 components: { headerBar },
 methods: {
 getPage (currentPage){
 console.log(currentPage);
 // this.$http.get("http://192.168.1.200/test.php").then(res=>{
 // console.log(res.data);
 // });
 },
 handleEdit(index, row) {
 console.log(index, row);
 },
 handleDelete(index, row) {
 console.log(index, row);
 },
 save(){
 if(this.formStatus.username == ""){
  alert("輸入名稱");
  return false;
 }
 console.log(typeof(this.formStatus.zhuhuType));
 if(typeof(parseInt(this.formStatus.zhuhuType)) != "number"){
  alert("輸入住戶類型");
  return false;
 }
 if(this.formStatus.shebeiType.length == 0 ){
  alert("輸入設備名稱");
  return false;
 }
 if(this.formStatus.zhuhudaxiao == 0){
  alert("選擇住戶大小");
  return false;
 }
 if(this.formStatus.userword == ""){
  alert("輸入用戶留言");
  return false;
 }

 console.log(this.formStatus);
 console.log("####用戶名稱####");
 console.log(this.formStatus.username);

 console.log("####住戶類型####");
 console.log(this.zhuhuType);

 console.log("####設備名稱####");
 console.log(this.shebeiType);

 console.log("####住戶大小####");
 console.log(this.userDxselected);

 console.log("####用戶留言####");
 console.log(this.userword);
 },
 //住戶類型改變數(shù)據(jù)
 changeZh(index){
 this.zhuhuType.forEach(function(value, index){
  value.isChecked = false;
 });
 this.zhuhuType[index].isChecked = true;
 },
 //設備選擇改變數(shù)據(jù)
 changeSb(index){
 console.log(index);
 this.shebeiType[index].isChecked = !this.shebeiType[index].isChecked;
 }
 },
 created () {
 console.log("############");
 //用戶名稱
 this.formStatus.username = "用戶名稱返回的內容";

 //循環(huán)住戶類型
 this.zhuhuType = [{
 name: '小型住戶',
 id: '12',
 isChecked: false
 },{
 name: '中型住戶',
 id: '43',
 isChecked: false
 },{
 name: '大型住戶',
 id: '72',
 isChecked: true
 },{
 name: '超大型住戶',
 name: '設備6',
 id: '25',
 isChecked: false
 }];

 //循環(huán)設備名稱
 this.shebeiType = [{
 name: '設備1',
 id: '22',
 isChecked: true
 },{
 name: '設備2',
 id: '23',
 isChecked: false
 },{
 name: '設備3',
 id: '52',
 isChecked: true
 },{
 name: '設備6',
 id: '65',
 isChecked: false
 }];

 //住戶大小
 this.zhuhudaxiao = [{
 name: "100平米",
 id: 1,
 value: 1
 },{
 name: "80平米",
 id: 2,
 value: 2
 },{
 name: "70平米",
 id: 3,
 value: 3
 }];

 //住戶大小
 this.formStatus.zhuhudaxiao = 2;
 //用戶名稱
 this.formStatus.userword = "用戶留言返回的內容";
 // axios.get("/test.php").then(res=>{
 // this.table = this.table.concat(res.data.data);

 // console.log(res.data);
 // });
 }
 }
</script>
<style>
 select{height:40px;width:100px;}
 .el-button--mini, .el-button--mini.is-round{}
 *{margin:0;padding:0;font-family:"微軟雅黑";}
 button{height:40px;width:100px;margin-left:20px;}
 .item p{padding:10px 0;}
 .table, .page{
 width:900px;
 height:auto;
 margin:20px auto;
 }
 label{
 padding:10px 20px;
 margin:10px;
 border:1px solid #eee;
 }
 body{padding-top:80px;}
 .header{
 position:fixed;
 top:0;
 width:100%;
 background:#eee;
 }
 .header ul{
 height:80px;
 width:1000px;
 }
 .header ul li{
 float:left;
 width:200px;
 font-size:14px;
 line-height:80px;
 text-align:Center;
 }
 .header ul li a{
 display:block;
 }

</style>

相關文章

  • vue3.0透傳屬性和事件的使用方式舉例

    vue3.0透傳屬性和事件的使用方式舉例

    這篇文章主要給大家介紹了關于vue3.0透傳屬性和事件使用的相關資料,透傳attribute指的是傳遞給一個組件,卻沒有被該組件聲明為props或emits的attribute或者v-on事件監(jiān)聽器,需要的朋友可以參考下
    2024-01-01
  • Vue項目實現(xiàn)html5圖片上傳的示例代碼

    Vue項目實現(xiàn)html5圖片上傳的示例代碼

    本文主要介紹了Vue項目?html5圖片上傳,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • 前端通過vue調用后端接口導出excel表格基本步驟

    前端通過vue調用后端接口導出excel表格基本步驟

    在Vue前端項目中,可通過axios庫發(fā)送請求至后端獲取Excel下載鏈接,文中通過代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2024-10-10
  • Vue3后臺管理系統(tǒng)之創(chuàng)建和配置項目

    Vue3后臺管理系統(tǒng)之創(chuàng)建和配置項目

    后臺管理系統(tǒng)是我們日常開發(fā)學習經(jīng)常遇到的一個項目,下面這篇文章主要給大家介紹了關于Vue3后臺管理系統(tǒng)之創(chuàng)建和配置項目的相關資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-09-09
  • Vue-element-admin?導出json和導入json文件的方法

    Vue-element-admin?導出json和導入json文件的方法

    這篇文章主要介紹了Vue-element-admin導出json和導入json文件,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-06-06
  • Vue 如何向集合的頭部添加元素

    Vue 如何向集合的頭部添加元素

    在 Vue 中,如果要向集合的頭部添加元素,可以使用 JavaScript 的 unshift 方法或 Vue 的 $set 方法,本文給大家介紹Vue 向集合的頭部添加元素的方法,感興趣的朋友一起看看吧
    2023-12-12
  • vue項目中在可編輯div光標位置插入內容的實現(xiàn)代碼

    vue項目中在可編輯div光標位置插入內容的實現(xiàn)代碼

    這篇文章主要介紹了vue項目中在可編輯div光標位置插入內容的實現(xiàn)代碼,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-01-01
  • Pure admin-Router標簽頁配置與頁面持久化實現(xiàn)方法詳解

    Pure admin-Router標簽頁配置與頁面持久化實現(xiàn)方法詳解

    這篇文章主要介紹了Pure admin-Router標簽頁配置與頁面持久化實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習吧
    2023-01-01
  • Vue 使用依賴注入的方式共享數(shù)據(jù)的過程

    Vue 使用依賴注入的方式共享數(shù)據(jù)的過程

    賴注入的方式共享數(shù)據(jù)在Vue中是一種高級特性,它主要用于開發(fā)插件或庫,或者處理一些特殊的場景,這篇文章主要介紹了Vue 使用依賴注入的方式共享數(shù)據(jù),需要的朋友可以參考下
    2023-11-11
  • Monorepo風格的組件工程搭建示例詳解

    Monorepo風格的組件工程搭建示例詳解

    這篇文章主要介紹了Monorepo風格的組件工程搭建示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-02-02

最新評論