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>
  • 相关阅读:
    LR实战之Discuz开源论坛——安装及简介
    LR如何利用siteScope监控MySQL性能
    初学SSH(其一)
    使用JUnit单元测试入门
    理解java中【同步】和【死锁】
    LR性能测试应用
    (28)ElasticSearch分布式架构特点
    (27)ElasticSearch 复合查询
    (06)Gitlab设置开启自启动、关闭开机自启动
    (05)安装GitLab
  • 原文地址:https://www.cnblogs.com/lljun/p/11763591.html
Copyright © 2011-2022 走看看