盼什么没什么,怕什么来什么。那些忙于批评别人的人,都忘了检讨自己。生活就是这样,当你想昂着头走路时,你就得随时准备在地上趴着。
如何通过变量动态拼接url?
格式:<a :rel="nofollow noopener noreferrer" 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 :rel="nofollow noopener noreferrer" 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>
动态拼接结果为:
rel="nofollow noopener noreferrer" href=“index.shtml?other=yyy”
补充知识:vue全局变量apiurl
1、定义
在main.js里面定义
Vue.prototype.$apiUrl = " http://xxxxxxxxxx";
2、使用
在联调的时候
url: this.$apiUrl + "/xxxx(端口)"
以上这篇使用vue实现通过变量动态拼接url就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。