摘要:一、動態(tài)參數(shù)顯示 ajax異步請求后,接收到返回的data參數(shù)并顯示在前端 1.1 引入js,也加入了jQuery<script type="text/javascript" src="/js/vue.min.js"></script> <script type="te
一、動態(tài)參數(shù)顯示
ajax異步請求后,接收到返回的data參數(shù)并顯示在前端
1.1 引入js,也加入了jQuery
<script type="text/javascript" src="/js/vue.min.js"></script> <script type="text/javascript" src="/js/jquery-2.1.3.js"></script>
1.2 html
<div id="app"> <p>{{ message }}</p> <button v-on:click="showData">顯示數(shù)據(jù)</button> </div>
1.3 JS
注意:這里JS一定要放在$(function() {})里面,或者是寫到body里面
new Vue({ el: '#app', data: { message: '' }, methods: { showData: function () { var _self = this; $.ajax({ type: 'GET', url: '...', success:function(data) { _self.message = JSON.stringify(data); } }); } } })
二、動態(tài)列表顯示
開始展示一個空白列表,ajax異步請求后,接收到返回的data列表信息并顯示
2.1 引入js,也加入了jquery
<script type="text/javascript" src="/js/vue.min.js"></script> <script type="text/javascript" src="/js/jquery-2.1.3.js"></script>
2.2 html
<div id="app"> <table> <thead> <tr> <th style='width:3%; text-align: left'>ID</th> <th style='width:5%; text-align: left'>名稱</th> <th style='width:10%; text-align: left'>條形碼</th> <th style='width:10%; text-align: left'>簡稱</th> </tr> </thead> <tbody> <tr v-for="goods in goodsList"> <td>{{goods.id}}</td> <td>{{goods.name}}</td> <td>{{goods.barcode}}</td> <td>{{goods.shortName}}</td> </tr> </tbody> </table> <button v-on:click="nameSearch()">查詢</button><br><br> </div>
2.3 JS
var goodsVue = new Vue({ el: '#app', data: { goodsList : '' }, methods: { nameSearch: function () { var _self = this; $.ajax({ type: 'GET', url: '...', success:function(data) { _self.goodsList = data; } }); } } })
更多關(guān)于Vue.js Ajax動態(tài)參數(shù)與列表顯示實例請關(guān)注PHP中文網(wǎng)(ipnx.cn)其他文章!