VUE踩坑記


  {
    path: '/test',
    name: 'Test',
    component: Test,
    // props: route => route.query        可以
    // props: { name: 'jjw', age: 19 }    可以
    props: route => ({ name: 'jjw', age: 19 })  //可以
    //props: route => { name: 'jjw', age: 19 }  編譯時報符號錯誤, 在age后的 : 下面紅波浪符號
  },

 組件

export default {
  name: 'Test',
  props: {
    /* name: '',
      age: 88

      13:11  error  The "name" property should be a constructor  vue/require-prop-type-constructor
      14:10  error  The "age" property should be a constructor   vue/require-prop-type-constructor 
    */
    name: String,
    age: Number
    // name: {    這樣也可以,上面的更簡單
    //   type: String
    // },
    // age: {
    //   type: Number
    // }
  },
  components: {
    TestMsg
  }
}

 

      <router-link :to="{path: '/Test', query: {name: 'jjw', age: 88, more: {a: 'aaa', b: 'bbb'}}}">Test</router-link> 復合對象不行
http://localhost:8080/#/Test?name=jjw&age=88&more=[object Object]  被解析成這樣

 隱藏 URL參數

  {
    path: '/test',
    name: 'test',   //這個很重要,區別大小寫
    component: Test
    // props: { name: '', age: 0 }
  },
export default {
  name: 'App',
  template: '#app',
  methods: {
    btnclick () {
      this.$router.push({
        name: 'test',    //這個很重要,區分大小寫
        params: {
          name: 'jjw',
          age: 100,
          other: {
            a: 'aaaa',
            b: 'bbbb'
          }
        }
      })
    }
  }
}
export default {
  name: 'Test',
  props: {
    name: String,
    age: Number
  },
  // data () {
  //   return {
  //     rp: {
  //       params: this.$route.params
  //     }
  //   }
  // },
  computed: {
    rp () {
      return this.$route.params
    }
  },
  components: {
    TestMsg
  }
}

// !!!命名路由傳參數
props 沒有用了, route.path 將是空值 !!!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM