vue如何通过变量动态拼接url

版权声明:如需转载,请带上本博客链接 https://blog.csdn.net/weixin_42869591/article/details/82873502

如何通过变量动态拼接url?
格式:<a :href="'index.shtml?other='+object.name">这是一个动态链接</a>
需要注意的是href前要加上冒号,href最外层是双引号,中间是单引号。

<div class="tab-content" id="datatable">
	<div v-for="(object,index) in items">
		<!-格式如下,href前要加上冒号--->  
	   <a :href="'index.shtml?other='+object.name">这是一个动态链接</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”

猜你喜欢

转载自blog.csdn.net/weixin_42869591/article/details/82873502
今日推荐