Location 对象

1. Location 对象

  • Location 对象包含有关当前 URL 的信息。
  • Location 对象是 Window 对象的一个部分,可通过 window.location 属性来访问。

2. Location 对象属性
在这里插入图片描述

<!--作者:zhangfan
页面名称:Location 对象属性de使用方法--> 
<template>
  <div id="product-list-one">
    <button @click="locationBtn()">执行locationBtn</button>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
export default {
  data() {
    return {};
  },
  computed: {},
  methods: {
    locationBtn() {
      console.log(
        "==============" + "window.location.hash" + "==================="
      );
      console.log(window.location.hash);
      console.log(
        "==============" + "window.location.host" + "==================="
      );
      console.log(window.location.host);
      console.log(
        "==============" + "window.location.hostname" + "==================="
      );
      console.log(window.location.hostname);
      console.log(
        "==============" + "window.location.href" + "==================="
      );
      console.log(window.location.href);
      console.log(
        "==============" + "window.location.pathname" + "==================="
      );
      console.log(window.location.pathname);
      console.log(
        "==============" + "window.location.port" + "==================="
      );
      console.log(window.location.port);
      console.log(
        "==============" + "window.location.protocol" + "==================="
      );
      console.log(window.location.protocol);
      console.log(
        "==============" + "window.location.search" + "==================="
      );
      console.log(window.location.search);
    }
  }
};
</script>

<style scoped>
</style>

在这里插入图片描述

3. Location 对象方法
在这里插入图片描述

<!--作者:zhangfan
页面名称:Location 对象属性de使用方法--> 
<template>
  <div id="product-list-one">
    <button @click="assignBtn()">执行assignBtn</button>
    <button @click="reloadBtn()">执行reloadBtn</button>
    <button @click="replaceBtn()">执行replaceBtn</button>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
export default {
  data() {
    return {};
  },
  computed: {},
  methods: {
    assignBtn() {
      window.location.assign("http://www.baidu.com");
    },
    reloadBtn() {
      window.location.reload();
    },
    replaceBtn() {
      window.location.replace("http://www.baidu.com");
    }
  }
};
</script>

<style scoped>
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值