概述
如何通过变量动态拼接url?
格式:<a :href="'index.shtml?other='+object.name" rel="external nofollow" rel="external nofollow" >这是一个动态链接</a>
需要注意的是href前要加上冒号,href最外层是双引号,中间是单引号。
<div class="tab-content" id="datatable"> <div v-for="(object,index) in items"> <!-格式如下,href前要加上冒号---> <a :href="'index.shtml?other='+object.name" rel="external nofollow" rel="external nofollow" >这是一个动态链接</a> </div> </div> <script> $(document).ready(function() { App.init(); //数据列表 var datatable = new Vue({ el: '#datatable', data: { items: [], }, }); //从服务端获取数据 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>
动态拼接结果为:
href=“index.shtml?other=yyy”
补充知识:vue全局变量apiurl
1、定义
在main.js里面定义
Vue.prototype.$apiUrl = " http://xxxxxxxxxx";
2、使用
在联调的时候
url: this.$apiUrl + "/xxxx(端口)"
以上这篇使用vue实现通过变量动态拼接url就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持靠谱客。
最后
以上就是温柔小蝴蝶为你收集整理的使用vue实现通过变量动态拼接url的全部内容,希望文章能够帮你解决使用vue实现通过变量动态拼接url所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复