欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue2.0數(shù)據(jù)雙向綁定與表單bootstrap+vue組件

 更新時間:2017年02月27日 11:02:37   投稿:mrr  
這篇文章主要介紹了vue2.0數(shù)據(jù)雙向綁定與表單bootstrap+vue組件,非常不錯,具有參考借鑒價值,需要的朋友可以參考下

最近一直在用vue,覺得確實是好用。

一,拿數(shù)據(jù)的雙向綁定來說吧

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>demo1</title>
</head>
<body>
  <div id="app">
{{ name }}
    <input type="text" v-model="name">
  </div>
</body>
<script type="text/javascript" src="vue.js"></script>
<script>
  new Vue({
    el: '#app',
    data: {
      name: ''
    },
    watch: {
      name: function () {
        console.log(this.name);
      }
    }
  });
</script>
</html>

vue中的所有數(shù)據(jù)都是在data中定義的,

el是指的掛載的元素,

watch 是我可以檢測某個數(shù)據(jù)的變化。

v-model=“name” 就是與data中的name數(shù)據(jù)綁定,input框中的值變,那么data中的name也會變,我們可以通過差值操作,也就是{{name}}來看到變化,當然也可以像我一樣打log。都是可以的。

當然這樣也許還不是很實用,官網(wǎng)上也是這么介紹的,那么就說我在工作中是怎么用的吧

現(xiàn)在我的需求是要得到我表單里邊的所有value ,我們也許可以       

 let service = $('.vendor').val();
        let vendor = document.getElementsByClassName('vendor')[0].value;

但是這樣就完全沒有get到vue雙向綁定的好處了,那么我們該怎么做呢?

import service from './components/service.vue';
  import $ from 'jquery';
  export default {
    data () {
      return {
        resultData: '',
        vendor: '',
        dType: '',
        services: [service],
        items: [service],
        device: '',
        dDesc: ''
      }
    },
    watch: {
      services () {
        console.log(this.services);
      },
      items (val) {
        this.items = val;
        console.log(this.items);
      }
    },
    components: {
      service
    },
    methods: {
      addService (component) {
        this.items.push(component);
      },
      childServicesChange (val) {
        this.services = val;
      },
      commit () {
        console.log('commit');
        let device = {
          "type": 'urn:' + this.vendor + ':device:' + this.dType + ':0000',
          "description": this.dDesc,
          "services": this.items
        };

看到?jīng)],我就是直接用的this.vendor, vendor是在data中定義好的,也進行了雙向綁定v-model

<template>
  <div class="devDesc">  

     Device Description

<form class="form-horizontal" role="form" ref="form" id="form">
    <div class="form-group">
      <label for="vendor" class="col-sm-2 control-label text-left">vendor:</label>
      <div class="col-sm-2">
        <input type="text" class="form-control vendor" id="vendor" v-model="vendor" control-label name="vendor">
      </div>
    </div>
    <div class="form-group">
      <label for="dType" class="col-sm-2 control-label text-left">Type:</label>
      <div class="col-sm-2">
        <input type="text" class="form-control dType" id="dType" v-model="dType" control-label name="dType">
      </div>
    </div>
    <div class="form-group">
      <label for="dDesc" class="col-sm-2 control-label text-left">description:</label>
      <div class="col-sm-2">
        <input type="text" class="form-control dDesc" id="dDesc" v-model="dDesc" control-label name="dDesc">
      </div>
    </div>
      <!--<serList class="serListPad" :services="services" @services-change="servicesChange">-->
      <!--</serList>-->
      <!--發(fā)現(xiàn)這個serList不用抽出來組件-->
    <div class="serList serListPad">
      <section class="serList-section">
          <span class="span-serList">service List</span>
          <button type="button" class="btn btn-default btn-sm" @click="addService(service)">
            <span class="glyphicon glyphicon-plus"></span>
          </button>
      </section>
      <!--<service v-for="item in items" :items="items" :myService="myService" @child-services-change="childServicesChange"></service>-->
      <div v-for="service in services">
        <service v-for="item in items" :items="items" :service="service" @child-services-change="childServicesChange"></service>
      </div>
    </div>
    </form>
    <button class="btn btn-info" @click="commit">commit</button>
    <button class="btn btn-success">save</button>
  </div>
</template>

以上所述是小編給大家介紹的vue2.0數(shù)據(jù)雙向綁定與表單bootstrap+vue組件,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關文章

  • 一文詳解Vue中過濾器filters的使用

    一文詳解Vue中過濾器filters的使用

    Vue.js允許自定義過濾器,過濾器的作用可被用于一些常見的文本格式化(也就是修飾文本,但是文本內容不會改變),本文主要來和大家講講過濾器filters的使用,感興趣的可以了解一下
    2023-04-04
  • Vue指令工作原理實現(xiàn)方法

    Vue指令工作原理實現(xiàn)方法

    自定義指令是 vue 中使用頻率僅次于組件,其包含 bind 、 inserted 、 update 、 componentUpdated 、 unbind 五個生命周期鉤子,接下來通過本文給大家詳細介紹Vue指令工作原理實現(xiàn)方法,需要的朋友參考下吧
    2021-06-06
  • nodejs讀取并去重excel文件

    nodejs讀取并去重excel文件

    給大家?guī)硪黄P于用nodejs實現(xiàn)excel文件的讀取并去重的功能,有興趣的朋友參考學習下。
    2018-04-04
  • Vue組件之高德地圖地址選擇功能的實例代碼

    Vue組件之高德地圖地址選擇功能的實例代碼

    這篇文章主要介紹了Vue組件之 高德地圖地址選擇功能的實例代碼,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-06-06
  • 關于axios的proxy代理配置解析

    關于axios的proxy代理配置解析

    這篇文章主要介紹了關于axios的proxy代理配置解析,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • webpack搭建vue 項目的步驟

    webpack搭建vue 項目的步驟

    這篇文章主要介紹了webpack搭建vue 項目的步驟,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-12-12
  • 基于 Vue 的樹形選擇組件的示例代碼

    基于 Vue 的樹形選擇組件的示例代碼

    本篇文章主要介紹了基于 Vue 的樹形選擇組件的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-08-08
  • Vue?3?表格時間監(jiān)控與動態(tài)后端請求觸發(fā)詳解?附Demo展示

    Vue?3?表格時間監(jiān)控與動態(tài)后端請求觸發(fā)詳解?附Demo展示

    在Vue3中,使用el-table組件渲染表格數(shù)據(jù),通過el-table-column指定內容,時間點需前端校準,用getTime()比較,到達時觸發(fā)操作,異步API請求可用async/await處理,setInterval實現(xiàn)定時監(jiān)控,配合條件判斷防止重復請求
    2024-09-09
  • 如何使用Vue+Element做個個人中心

    如何使用Vue+Element做個個人中心

    我們在做了用戶登錄后,就會讓用戶跳轉到個人中心,下面這篇文章主要給大家介紹了關于如何使用Vue+Element做個個人中心的相關資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-06-06
  • vue-cli 環(huán)境變量 process.env的使用及說明

    vue-cli 環(huán)境變量 process.env的使用及說明

    這篇文章主要介紹了vue-cli 環(huán)境變量 process.env的使用及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-12-12

最新評論