router-link傳遞參數

<router-link
  :to="{ name: 'MyRouter', query: { username: '張三' } }"
  >點擊獲取用戶名</router-link
>

在路由名爲MyRouter的組件中,進行打印測試:

console.log(this.$route.query.username)

建議寫computed中,然後繼續獲取:

  computed: {
    cpntTitle: function() {
      return this.$route.query.username
  }

html中:

<span>{{ cpntTitle }}</span>

methods中:

methods: {
	printCpntTitle() {
		console.log(this.cpntTitle)
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章