使用vue實現(xiàn)通過變量動態(tài)拼接url
如何通過變量動態(tài)拼接url?
格式:<a :href='http://m.lshqa.cn/bcjs/’index.shtml?other=’+object.name' rel='external nofollow' rel='external nofollow' >這是一個動態(tài)鏈接</a>
需要注意的是href前要加上冒號,href最外層是雙引號,中間是單引號。
<div id='datatable'><div v-for='(object,index) in items'><!-格式如下,href前要加上冒號---> <a :href='http://m.lshqa.cn/bcjs/’index.shtml?other=’+object.name' rel='external nofollow' rel='external nofollow' >這是一個動態(tài)鏈接</a></div></div><script> $(document).ready(function() { App.init(); //數(shù)據(jù)列表 var datatable = new Vue({ el: ’#datatable’, data: {items: [], }, }); //從服務(wù)端獲取數(shù)據(jù) getList(); function getList() { $.ajax({url : '/sapi/getcluster',type : 'post',dataType : 'json',success : function(result){ if(result.status == -1){ window.location.href = result.data; return false; } datatable.items = result.data['XXX'];} }); } });</script>
動態(tài)拼接結(jié)果為:
href=“index.shtml?other=yyy”
補充知識:vue全局變量apiurl
1、定義
在main.js里面定義
Vue.prototype.$apiUrl = ' http://xxxxxxxxxx';
2、使用
在聯(lián)調(diào)的時候
url: this.$apiUrl + '/xxxx(端口)'
以上這篇使用vue實現(xiàn)通過變量動態(tài)拼接url就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Python基于traceback模塊獲取異常信息2. python開發(fā)一個解析protobuf文件的簡單編譯器3. ASP編碼必備的8條原則4. python 根據(jù)列表批量下載網(wǎng)易云音樂的免費音樂5. python中round函數(shù)保留兩位小數(shù)的方法6. python 基于AioHttp 異步抓取火星圖片7. 利用python+ffmpeg合并B站視頻及格式轉(zhuǎn)換的實例代碼8. 解決Python數(shù)據(jù)可視化中文部分顯示方塊問題9. C語言字符串轉(zhuǎn)換為Python字符串的方法10. 深入理解JavaScript字節(jié)二進(jìn)制知識以及相關(guān)API
