zoukankan      html  css  js  c++  java
  • vue-vue页面之间的传值

    1. router-link标签跳转

    • 不需要传参
    <router-link to='two'><button>点我到第二个页面</button></router-link>
    
    • id传参

      • 传参页面

        <!--<router-link :to="{'path':'/要跳转的路由/','query':{'id':sect.id}}">上传课程</router-link>-->
        
      • 跳转页面

        data() {
              return {
                course:{},
                id :this.$route.query.id+ "/"  , #从路由中获取参数id
              },
        }
        

    2.点击事件跳转

    • 不需要传参
    html :
        <button @click="hreftwo" class="test-one">点我到第二个页面</button>js   :
        methods:{
             //跳转页面
             hreftwo(){
                 this.$router.push({path:'/two'})
             }
         }
    
    • 需要传参

      • 传参页面
      <template>
        <div>
          <div v-for="good in goods">
            <a>标题:{{good.title}}</a>
            <a v-if="uid">价格:{{good.v_price}}</a>
            <a v-else>价格:{{good.price}}</a>
            <a><img :src="'http://127.0.0.1:8000/'+good.img" style=" 100px"></a>
            
            <button @click="add_order(good.title,good.price)">提交订单</button>
            <!--<router-link :to="{'path':'/order/','query':{'title':good.title,'price':good.price}}">提交订单</router-link>-->
            <div style="border:1px solid #CCC"></div>
          </div>
      
        </div>
      </template>
      
      <script>
        export default {
          name: "GoodsLIst",
          data() {
            return {
              goods: [],
              title:'',
              price:''
            }
          },
          methods: {
            add_order(title,price) {
              if (!this.uid) {
                this.$router.push('/login')
              } else {
                   <!--// http://127.0.0.1:8080/order?title=***&price=***-->
                this.$router.push({path:'/order?title='+title+'&price='+price})
              }
            }
          }
      
        }
      </script>
      
      <style scoped>
      
      </style>
      
      
      • 跳转页面可以在要跳转的页面上使用this.$route.query.id, 从路由中获取参数
      data() {
            return {
              course:{},
              id :this.$route.query.id+ "/"  , #从路由中获取参数id
            },
      }
      
    从小白到大神的蜕变~~
  • 相关阅读:
    开通博客园
    ios关键字
    FirstDay
    An example for pysnmp
    remove debug symbols to a seperate file
    qemu下通过gdb调试内核时 遇到 evaluation of this expression requires the program to have a function "malloc" 错误的解决办法
    关于常识与知识的思考
    基于Qemu在ubuntu上构建linux学习环境
    How to download prebuilt toolchain
    诡异的打印异常BUG
  • 原文地址:https://www.cnblogs.com/tjw-bk/p/13823312.html
Copyright © 2011-2022 走看看