[英]How to pass variable data between components in Vue js
在這里,我試圖將變量 header_url 數據傳遞給我的其他 vue 頁面。 因為我也想在其他 vue 腳本標簽中使用它來推送和發布方法。 我不知道該怎么做? 因為,我只能找到在 html 標簽之間傳輸數據的示例。
// Home.vue
<template>
<div>
Home
<h2>logout</h2>
<a v-bind:href="url">logout</a>
</div>
</template>
<script>
export default {
data: () => ({
url:"https:..."
})
}
var header_url = window.location.href;
if (header_url.length>100) {
var token=window.location.href.match(/\#(?:id_token)\=([\S\s]*?)\&/)[1]; // eslint-disable-line
console.log(token);
}
</script>
要在單頁應用程序中的兩個 URL 之間傳遞數據,您需要使用Vue Router和Route Meta Fields 。
從文檔:
有時,您可能希望將任意信息附加到路由,例如轉換名稱、誰可以訪問路由等。這可以通過接受 object 屬性的元屬性來實現,並且可以在路由位置和導航守衛上訪問
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.