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")); } ); },