weixin_43655885
新前新端新程新序新员
采纳率0%
2018-12-20 15:12

请问VUE不用路由 怎么获取 URL 上面的参数

http://www.123.com/apilist.html?proTypeID=201518

请问VUE不用路由 怎么直接获取 URL 上面的 proTypeID
<div id="pro_list">
  <ul>
    <template v-for="(item,index) in itemList.slice(0,6)">
    <li> <span>序号:{{index+1}}</span><span>编号:{{item.id}}</span><span>所属类别:{{item.typename}}</span><span>所属类别编号:{{item.typeid}}</span><span>名称:{{item.name}}</span><span>时间:{{item.date}}</span><span>简介:{{item.name20}}</span><span>图片:<a
                             target="_blank" :href="'apidisplay.html?proID='+item.id" :title="item.name"><img :alt="item.name" :src="item.big" /></a></span></li>
    </li>
    </template>
  </ul>
</div>
<script type="text/javascript">
    var app = new Vue({
        el: "#pro_list",
        data: {
            itemList: [],

        },
        methods: {
                    getData: function () {
                        var abc = this;
                        var proTypeID = 201518;
                        var pageMax=2;
                        this.$http.jsonp("listProductsAction.do").then(shuju);
                        function shuju(changdu) {
                            console.log(changdu);
                            for (var i = 0, len = changdu.data.list.length; i < len; i++) {
                                //if (changdu.data.list[i].typeid == proTypeID && changdu.data.list[i].isnewly=='0'){ }
                                    var selData = changdu.data.list[i];
                                    var id = changdu.data.list[i].id;
                                    var typename = changdu.data.list[i].typename;
                                    var typeid = changdu.data.list[i].typeid;
                                    var name = changdu.data.list[i].name;
                                    var date = changdu.data.list[i].date;
                                    var name20 = changdu.data.list[i].name20;
                                    var big = changdu.data.list[i].big;
                                    this.itemList.push(selData);

                            }
                        }
                    }
        },
        mounted: function () {
        console.log(this);
        this.getData();
    }
});
</script>

这是我的解决方案,有没有别的方法?

<script type="text/javascript">
  function GetUrlParam(paraName) {
    var url = document.location.toString();
    var arrObj = url.split("?");

    if (arrObj.length > 1) {
      var arrPara = arrObj[1].split("&");
      var arr;

      for (var i = 0; i < arrPara.length; i++) {
        arr = arrPara[i].split("=");

        if (arr != null && arr[0] == paraName) {
          return arr[1];
        }
      }
      return "";
    }
    else {
      return "";
    }
  }
var proTypeID=GetUrlParam("proTypeID");
</script>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • weixin_43655885 新前新端新程新序新员 3年前
    <script type="text/javascript">
      function GetUrlParam(paraName) {
        var url = document.location.toString();
        var arrObj = url.split("?");
    
        if (arrObj.length > 1) {
          var arrPara = arrObj[1].split("&");
          var arr;
    
          for (var i = 0; i < arrPara.length; i++) {
            arr = arrPara[i].split("=");
    
            if (arr != null && arr[0] == paraName) {
              return arr[1];
            }
          }
          return "";
        }
        else {
          return "";
        }
      }
    var proTypeID=GetUrlParam("proTypeID");
    </script>
    
    点赞 评论 复制链接分享

相关推荐