使用vue實(shí)現(xiàn)通過變量動態(tài)拼接url
如何通過變量動態(tài)拼接url?
格式:<a :href='http://www.intensediesel.com/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://www.intensediesel.com/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”
補(bǔ)充知識:vue全局變量apiurl
1、定義
在main.js里面定義
Vue.prototype.$apiUrl = ' http://xxxxxxxxxx';
2、使用
在聯(lián)調(diào)的時(shí)候
url: this.$apiUrl + '/xxxx(端口)'
以上這篇使用vue實(shí)現(xiàn)通過變量動態(tài)拼接url就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. UDDI FAQs2. JSP之表單提交get和post的區(qū)別詳解及實(shí)例3. ASP基礎(chǔ)入門第三篇(ASP腳本基礎(chǔ))4. .NET SkiaSharp 生成二維碼驗(yàn)證碼及指定區(qū)域截取方法實(shí)現(xiàn)5. jsp網(wǎng)頁實(shí)現(xiàn)貪吃蛇小游戲6. html清除浮動的6種方法示例7. 將properties文件的配置設(shè)置為整個Web應(yīng)用的全局變量實(shí)現(xiàn)方法8. css進(jìn)階學(xué)習(xí) 選擇符9. jsp實(shí)現(xiàn)textarea中的文字保存換行空格存到數(shù)據(jù)庫的方法10. ASP.NET Core實(shí)現(xiàn)中間件的幾種方式
