最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue.js實(shí)現(xiàn)雙向數(shù)據(jù)綁定方法(表單自動賦值、表單自動取值)

 更新時(shí)間:2018年08月27日 10:13:27   作者:白楓J  
今天小編就為大家分享一篇Vue.js實(shí)現(xiàn)雙向數(shù)據(jù)綁定方法(表單自動賦值、表單自動取值),具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧

1、使用Vue.js實(shí)現(xiàn)雙向表單數(shù)據(jù)綁定,例子

<!--html代碼-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>財(cái)產(chǎn)查勘處理</title>
<link rel="stylesheet" type="text/css" href="../css/global.css" rel="external nofollow" />
<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css" rel="external nofollow" />
<link rel="stylesheet" type="text/css" href="../css/AdminLTE.min.css" rel="external nofollow" />
<link rel="stylesheet" type="text/css" href="../css/propertySurvey.css" rel="external nofollow" />
</head>
<body>
  <div class="container-fluid">
    <div style="text-align: center; height:30px;background:#F4F9FD;padding:10px 0px;border-bottom:1px solid #000; font-weight: bold;">請輸入物損查看信息</div>
    <h4 class="box-title">
      <i class="glyphicon glyphicon-play-circle" style="color: #82C542;"></i>
      報(bào)案信息
    </h4>
    <hr style="height: 3px; border: none; border-top: 3px solid #75C2D2;" />
    <div class="row text-center" style="margin-top: -23px; padding: 3px 50px; border-bottom: 1px solid #DBEEF1;">
      <div style="width: 33%; float: left; text-align: left;">
        <label>損失方</label><input v-model="RegistInfo_name" type="text" name="RegistInfo_name"/>
      </div>
      <div style="width: 33%; float: left; text-align: left;">
        <label>聯(lián)系人</label><input v-model="RegistInfo_user" type="text" name="RegistInfo_user"/>
      </div>
      <div style="width: 33%; float: right; text-align: left;">
        <label>聯(lián)系方式</label> <input v-model="RegistInfo_phone" name="RegistInfo_phone" type="text"/>
      </div>
    </div>
    <div class="row text-center" style="margin-top: -23px; padding: 3px 50px; border-bottom: 1px solid #DBEEF1;">
      <div style="width: 33%; float: left; text-align: left;">
        <label>損失方1</label><input v-model="Prplregist_name" type="text" name="Prplregist_name"/>
      </div>
      <div style="width: 33%; float: left; text-align: left;">
        <label>聯(lián)系人1</label><input v-model="Prplregist_user" type="text" name="Prplregist_user"/>
      </div>
      <div style="width: 33%; float: right; text-align: left;">
        <label>聯(lián)系方式1</label> <input v-model="Prplregist_phone" name="Prplregist_phone" type="text"/>
      </div>
    </div>
    <div class="row text-center" style="padding: 3px 50px; border-bottom: 1px solid #DBEEF1;">
      <div style="width: 33%; float: left; text-align: left;">
        <label>查勘估損金額</label> <input v-model="RegistInfo_chakan_money" name="RegistInfo_chakan_money" type="text" value="400.00" /> *
      </div>
      <div style="width: 33%; float: left; text-align: left;">
        <label>施救費(fèi)金額</label> <input v-model="RegistInfo_rescue_money" name="RegistInfo_rescue_money" type="text" name="" id="" value="0.00" />
      </div>
      <div style="width: 33%; float: right; text-align: left;">
        <label>需要施救</label> <input type="checkbox" />是否需要
      </div>
    </div>
    <div class="row text-center" style="padding: 3px 50px; border-bottom: 1px solid #DBEEF1;">
      <div style="width: 33%; float: left; text-align: left;">
        <label>查勘估損金額1</label> <input v-model="Prplregist_chakan_money" name="Prplregist_chakan_money" type="text" value="400.00" /> *
      </div>
      <div style="width: 33%; float: left; text-align: left;">
        <label>施救費(fèi)金額1</label> <input v-model="Prplregist_rescue_money" name="Prplregist_rescue_money" type="text" name="" id="" value="0.00" />
      </div>
      <div style="width: 33%; float: right; text-align: left;">
        <label>需要施救1</label> <input type="checkbox" />是<input type="checkbox" />沒錯(cuò)<input type="checkbox" />必須
      </div>
    </div>
    <div class="row text-center" style="padding: 3px 50px; border-bottom: 1px solid #DBEEF1;">
      <div style="width: 67%; float: left; text-align: left;">
        <label>查勘地點(diǎn)</label> <input v-model="address" name="address" type="text" style="width: 400px;" /> *
      </div>
      <div style="width: 33%; float: left; text-align: left;">
        <label>查勘日期</label> <input v-model="RegistInfo_chakan_data" name="RegistInfo_chakan_data" type="text" name="" id="" value="2017-03-09" />
      </div>
    </div>
    <div class="row text-center" style="padding: 3px 50px; border-bottom: 1px solid #DBEEF1;">
      <div style="height: 50px; text-align: left;">
        <label>施救過程描述</label> <input v-model="RegistInfo_say" name="RegistInfo_say" type="text" style="width: 900px; height: 50px;" />
      </div>
    </div>
    <div class="row text-center" style="padding: 3px 50px; border-bottom: 1px solid #DBEEF1;">
      <div style="height: 50px; text-align: left;">
        <label>備注</label> <input v-model="remark" name="remark" type="text" style="width: 900px; height: 50px;" />
      </div>
    </div>
    <div class="row text-center" style="padding: 3px 50px; border-bottom: 1px solid #DBEEF1;">
      <div style="height: 50px; text-align: left;">
        <select class="select2">
          <option value="123" id="sel1">123</option>
          <option value="456" id="sel2">456</option>
          <option value="789" id="sel3">789</option>
        </select>
      </div>
    </div>
    <div class="row text-center" style="padding: 3px 50px; border-bottom: 1px solid #DBEEF1;">
      <div style="height: 50px; text-align: left;">
        <input type="radio" id="google" value="Google" v-model="RegistInfo_radio" name="RegistInfo_radio">
        <label for="google">Google</label>
        <br>
        <input type="radio" id="runoob" value="Runoob" v-model="RegistInfo_radio" name="RegistInfo_radio">
        <label for="runoob">Runoob</label>
      </div>
    </div>
    <div class="row text-center" style="padding: 3px 50px; border-bottom: 1px solid #DBEEF1;">
      <div style="height: 50px; text-align: left;">
        <input type="radio" id="helongjun" value="helongjun" v-model="RegistInfo_helongjun" name="RegistInfo_helongjun">
        <label for="helongjun">helongjun</label>
        <br>
        <input type="radio" id="longjun" value="longjun" v-model="RegistInfo_helongjun" name="RegistInfo_helongjun">
        <label for="longjun">longjun</label>
      </div>
    </div>
    <div class="row text-center" style="padding: 3px 50px; border-bottom: 1px solid #DBEEF1;">
      <div style="height: 50px; text-align: left;">
        <input type="radio" id="testOne" value="testOne" v-model="testOne" name="testOne">
        <label for="helongjun">testOne</label>
        <br>
        <!--<input type="radio" id="testOne" value="testTwo" v-model="testOne" name="testOne">
        <label for="longjun">testTwo</label>-->
      </div>
    </div>
    <div class="row text-center" style="padding: 3px 50px; border-bottom: 1px solid #DBEEF1;">
      <div style="height: 50px; text-align: left;">
        <select v-model="RegistInfo_selected" name="RegistInfo_selected">
          <option value="">選擇一個(gè)網(wǎng)站</option>
          <option value="baidu">baidu</option>
          <option value="google">Google</option>
        </select>
      </div>
    </div>
    <div class="text-center row">
      <button>暫存(S)</button>
      <button onclick="getInputVal()">返回(F)</button>
    </div>
  </div>
  <script type="text/javascript" src="../js/vue.min.js" ></script>
  <script type="text/javascript" src="../js/jquery-1.11.0.min.js"></script>
  <script type="text/javascript" src="../js/bootstrap.min.js"></script>
  <script type="text/javascript" src="../js/bootstrap-datetimepicker.min.js"></script>
  <script type="text/javascript" src="../VueFormSub.js" ></script>
#VueFormSub.js(實(shí)現(xiàn)雙向綁定主要代碼)

//實(shí)現(xiàn)取值
var VueFormSub = function(formid){
  this.$form = ($("#" + formid).length !=0)?$("#" + formid):$("."+formid);
  var models = $("*[v-model != '']", this.$form);
  var vueData = {};
  $.each(models,function(idx,dom){
    var key = $(dom).attr("name");
    if (undefined != key){
      var dValue = $(dom).val();
      $(dom).val(dValue);
      var beanName = key.split("_");
      if(beanName.length < 2){
        vueData[beanName] = dValue;
        vueData[beanName] = $("input[type='radio'][name='"+key+"']:checked").val();
      }else{
        if(vueData[beanName[0]] == undefined){
          vueData[beanName[0]] = {};
        }else{
          if($(dom).attr("type") == "radio"){
            var tempVal = $("input[type='radio'][name='"+key+"']:checked").val();
            vueData[beanName[0]][beanName[1]] = tempVal;
          }else{
            vueData[beanName[0]][beanName[1]]=dValue;            
          }
        }
      }
    }
  });
  return vueData;
};

#初始化Vue表單數(shù)據(jù)(可以只傳入initDate數(shù)據(jù)源,formid需要綁定的dom)
VueFormSub.initVue = function(initDate,formid,httpMethod, url, params){
  if(initDate instanceof Object){
    /*if(initDate.length !=0){}*/
    var initJson = VueFormSub.ObjConvert(initDate);
    new Vue({
      el : ($("#"+formid).length != 0)?'#'+formid:'.'+formid,
      data : initJson
    });
  }else{
    if (httpMethod != "get" && params && typeof (params) == "object"){
      params = JSON.stringify(params);
    }
    if(params!= null){
      params.rs = Math.random();
    }else{
      params = {'rs':Math.random()};
    }
    $.ajax({
      type: httpMethod,
      url: "/cxh" + url,
      data: params,
      cache:false,
      async: true,
      contentType: 'application/json',
      dataType: 'json',
      success: function (returnData) {
        if(returnData.length != 0){
          var vueDate = VueFormSub.ObjConvert(returnData);
          new Vue({
            el:($("#"+formid).length != 0)?'#'+formid:'.'+formid,
            data : vueDate
          });
        }
      }
    });
  }
};

#對需要綁定的對象進(jìn)行解析成Vue支持的格式
VueFormSub.ObjConvert = function(dataObj){
  var json = {};
  $.each(dataObj,function(id,param){
    if(param instanceof Object){
      $.each(param, function(rid,rparam){
        if(rparam instanceof Object){
          json[id] = VueFormSub.ObjConvert(param);
        }else{
          json[id+"_"+rid] = rparam;
        }
      });
    }else{
      json[id]=param;
    }
  });
  return json;
};
#使用實(shí)例
<script>
  #初始化數(shù)據(jù)data
  var initVue = {
    RegistInfo_name : 'legend',
    RegistInfo_user : '龍軍',
    RegistInfo_phone : '1008611',
    RegistInfo_chakan_money : '100',
    RegistInfo_rescue_money : '1000',
    address : '廣東省汕頭市潮南區(qū)',
    RegistInfo_chakan_data : '2017-5-7',
    RegistInfo_say : '這個(gè)只是測試用的',
    remark : '龍軍用來測試的',
    Prplregist_name : '林總',
    Prplregist_user : '林老板',
    Prplregist_phone : '10010',
    Prplregist_chakan_money : '一萬塊',
    Prplregist_rescue_money : '一個(gè)億',
    RegistInfo_radio : "Runoob",
    RegistInfo_selected : "google",
    RegistInfo_helongjun : "helongjun",
    testOne:""
  };
  //初始化Vue表單
  VueFormSub.initVue(initVue,"container-fluid");
  //返回按鈕單擊
  function getInputVal(){
    //調(diào)用自動表單封裝
    var resultVal = new VueFormSub("container-fluid");
    console.log(resultVal);
  }
#注意:input表單中的name屬性必須指定,最好和input表單中的v-model的值一樣
<script>

最終效果:

以上這篇Vue.js實(shí)現(xiàn)雙向數(shù)據(jù)綁定方法(表單自動賦值、表單自動取值)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 深入解析vue中的權(quán)限管理

    深入解析vue中的權(quán)限管理

    權(quán)限是對特定資源的訪問許可,所謂權(quán)限控制,也就是確保用戶只能訪問到被分配的資源,這篇文章主要介紹了vue的權(quán)限管理的相關(guān)知識,需要的朋友可以參考下
    2022-06-06
  • Vue2中Element?UI表單的使用詳解

    Vue2中Element?UI表單的使用詳解

    這篇文章主要為大家詳細(xì)介紹了Vue2中Element?UI表單的使用,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-03-03
  • vue實(shí)現(xiàn)form表單與table表格的數(shù)據(jù)關(guān)聯(lián)功能示例

    vue實(shí)現(xiàn)form表單與table表格的數(shù)據(jù)關(guān)聯(lián)功能示例

    這篇文章主要介紹了vue實(shí)現(xiàn)form表單與table表格的數(shù)據(jù)關(guān)聯(lián)功能,涉及vue.js表單事件響應(yīng)及頁面元素屬性動態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2019-01-01
  • Vue 中 onclick和@click區(qū)別解析

    Vue 中 onclick和@click區(qū)別解析

    這篇文章主要介紹了Vue 中 onclick和@click區(qū)別,簡單點(diǎn)說就是onclick 只能觸發(fā) js的原生方法,不能觸發(fā)vue的封裝方法,@click 只能觸發(fā)vue的封裝方法,不能觸發(fā)js的原生方法,需要的朋友可以參考下
    2024-02-02
  • vue+elementUI下拉框回顯問題及解決方式

    vue+elementUI下拉框回顯問題及解決方式

    這篇文章主要介紹了vue+elementUI下拉框回顯問題及解決方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-02-02
  • vue.js實(shí)現(xiàn)請求數(shù)據(jù)的方法示例

    vue.js實(shí)現(xiàn)請求數(shù)據(jù)的方法示例

    這篇文章主要給大家介紹了vue.js實(shí)現(xiàn)請求數(shù)據(jù)的方法示例,文中分別介紹了vue1.0和vue2.0的示例方法,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-02-02
  • 基于vue-router的matched實(shí)現(xiàn)面包屑功能

    基于vue-router的matched實(shí)現(xiàn)面包屑功能

    本文主要介紹了基于vue-router的matched實(shí)現(xiàn)面包屑功能,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • vue指令?v-bind的使用和注意需要注意的點(diǎn)

    vue指令?v-bind的使用和注意需要注意的點(diǎn)

    這篇文章主要給大家分享了?v-bind的使用和注意需要注意的點(diǎn),下面文章圍繞?v-bind指令的相關(guān)資料展開內(nèi)容且附上詳細(xì)代碼?需要的小伙伴可以參考一下,希望對大家有所幫助
    2021-11-11
  • Vue中靈活拖拽的前端神器VueDraggablePlus的用法詳解

    Vue中靈活拖拽的前端神器VueDraggablePlus的用法詳解

    這篇文章主要介紹了一款功能強(qiáng)大、靈活易用的前端組件VueDraggablePlus,作為前端工程師,我們經(jīng)常會遇到需要實(shí)現(xiàn)拖拽功能的場景,而VueDraggablePlus正是為了解決這一痛點(diǎn)而誕生的,讓我們一起來看看它的特點(diǎn)和用法吧
    2024-03-03
  • vue實(shí)現(xiàn)組件切換效果的三種功能

    vue實(shí)現(xiàn)組件切換效果的三種功能

    這篇文章主要為大家介紹了在Vue中實(shí)現(xiàn)組件切換的三種方法,即使用條件渲染,使用動態(tài)組件以及通過點(diǎn)擊按鈕切換組件,有需要的小伙伴可以了解下
    2024-11-11

最新評論

富平县| 客服| 堆龙德庆县| 阳西县| 万载县| 寿光市| 阿鲁科尔沁旗| 綦江县| 金湖县| 元阳县| 武隆县| 牙克石市| 靖西县| 江津市| 石泉县| 武邑县| 泗水县| 子洲县| 什邡市| 剑川县| 新绛县| 潢川县| 伊宁县| 舟山市| 涞水县| 行唐县| 攀枝花市| 吉隆县| 巫山县| 辉县市| 长岭县| 那曲县| 桂阳县| 华亭县| 延川县| 新邵县| 碌曲县| 白河县| 文安县| 濮阳县| 九龙坡区|