zoukankan      html  css  js  c++  java
  • vue路由传参params和query

    1、params传参页面

    <template>

      <button @click="params()">params传参</button>

    </template>

    <script>
        export default {
       methods: {
          params() {
            this.$router.push({
              name: 'about',
              params: {
                page: '1',
                code: '1234'
              }
            })
          }
        }
          }
    </script>
    params接收参数页面
    <script>
      export default {
        data () {
          return {
            page: '',
            code: ''
          }
        },
      created () {
          this.routerData()
        },
        methods: {
          routerData () {
            this.page = this.$route.params.page
            this.code = this.$route.params.code
            console.log('page', this.page)
            console.log('code', this.code)
          }
        }
      }
    </script>
    使用params接收的参数如果强制刷新后数据会消失,所以最好使用query进行传参

    2、query传参页面

    <template>

      <button @click="query()">query传参</button>

    </template>

    <script>
        export default {
       methods: {
          query () {
            this.$router.push({
              name: 'about',
              query: {
                page: '1',
                code: '1234'
              }
            })
          }
        }
          }
    </script>
    query接收参数页面
    <script>
      export default {
        data () {
          return {
            page: '',
            code: ''
          }
        },
      created () {
          this.routerData()
        },
        methods: {
          routerData () {
            this.page = this.$route.query.page
            this.code = this.$route.query.code
            console.log('page', this.page)
            console.log('code', this.code)
          }
        }
      }
    </script>
  • 相关阅读:
    ReactiveCocoa RACObserve subscribeNext 时,只有值不一样时才响应
    ReactiveCocoa 监听Enabled和添加Command出错的处理方法
    Masonry + UIView Animations 注意事项
    addObserver forKeyPath options 注意事项
    ios中tabbar得title和navigationbar的title如何修改
    tableview 分组显示返回footerviewt和headerView的高度不能为0的问题
    UITableViewCell的选中时的颜色设置
    ios 枚举 位移操作
    设置UIButton 字体 颜色
    jsoup 源码分析
  • 原文地址:https://www.cnblogs.com/lljun/p/11763591.html
Copyright © 2011-2022 走看看