vue获得当前页面URL动态拼接URL复制邀请链接方法

vue获得当前页面URL动态拼接URL复制邀请链接方法

当前页面完整url可以用 location.href
路由路径可以用 this.$route.path
路由路径参数 this.$route.params
实例:动态邀请链接,获得当前页面URL去掉path,替换成注册的加上邀请码:
this.invitelink = location.href.replace(this.$route.path,'') + "/register?invitecode=" + this.invitecode;

a标签的写法
<!-格式如下,href前要加上冒号--->
<a :href="'index.shtml?other='+object.name">这是一个动态链接</a>
<a :href="'${request.contextPath}/admin/getId/'+r.id">编辑</a>

===============
复制邀请链接方法:
main.js里添加:
import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard)
-----------
页面使用方法:

copyInvitelink(){
 var this_ = this;
 this.$copyText(this.invitelink).then(
 function(e) {
    Toast.info(this_.$t("my.copedLink"));
 },
 function(e) {
    console.log(this_.$t("my.copeErr"));
 }
 );
},
原文地址:https://www.cnblogs.com/zdz8207/p/vue-clipboard2-url-route-invitecode.html