欢迎来到代码驿站!

当前位置:首页 >

使用vue实现通过变量动态拼接url

时间:2020-07-22 23:23:51|栏目:|点击:

如何通过变量动态拼接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(端口)"

上一篇:PHP代码覆盖率统计详解

栏    目:

下一篇:R语言ggplot2边框背景去除的实现

本文标题:使用vue实现通过变量动态拼接url

本文地址:http://www.codeinn.net/misctech/2443.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有