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>
  • 相关阅读:
    Myeclipse导出war包
    报表移动端如何进行移动设备绑定与撤销
    MySQL检查运行的mysqld服务器是否支持OpenSSL
    JavaScript替换字符串中最后一个字符
    dns 添加域名
    连接linux系统sftp下载文件
    8.1 Optimization Overview
    Chapter 8 Optimization
    19.6.1 Partitioning Keys, Primary Keys, and Unique Keys 分区键,主键,和唯一健
    Web报表页面如何传递中文参数
  • 原文地址:https://www.cnblogs.com/lljun/p/11763591.html
Copyright © 2011-2022 走看看