vue 1.x 互動實現仿百度下拉式清單樣本,vue1.x

來源:互聯網
上載者:User

vue 1.x 互動實現仿百度下拉式清單樣本,vue1.x

0、前言

vue 本身不支援互動,想要做互動,必須引入ajax 模組。vue 團隊提供一個新的庫檔案叫做 vue-resource.js 。

網路CDN:https://cdn.bootcss.com/vue-resource/1.3.4/vue-resource.js

1、用法分類

ajax 互動通常分為3類,get,post,jsonp

html 部分的代碼:數組myData 的資料通過ul 列表顯示出來,用"v-for"指令

<body>     <div id="box">      <input type="text" value="" v-model="m" @keyup="get()">      {{m}}<br/>      {{msg}}<br/>      {{'welcome'|uppercase}}      <ul>        <li v-for="value in myData">          {{value}}        </li>      </ul>      <p v-show="myData.length == 0">暫無資料</p>    </div> </body>

1) get 請求

methods:{  get: function(){    this.$http.get('search',{      wd:this.m  }).then(function(res){  this. myData= res.body  },function(res){  console.log(res.status)})}  }

2)post 請求

methods:{get : function () {          this.$http.post('search',{            wd:this.m          },{            emulateJSON:true,   //在get 請求的基礎上添加了第3個參數          }).then(function(res){            this.myData=res.body;          },function(res){            console.log('err---');            // alert(2)            //this.myData = ['aaa', 'a111', 'a222'];          })                  }}

在後台項目中,調試運行結果如下:

輸入關鍵字“a”後,進入斷點,擷取資料:

3)jsonp 能夠發送跨域請求,用的不多,不在此贅述

2、總結:

本片文章要求掌握get 和post 請求的寫法,v-model 雙向繫結資料,列表中運用v-for顯示數組的資料,v-show 後面接條件控制資料顯示與否

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援幫客之家。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.