zoukankan      html  css  js  c++  java
  • vue传参

    <template>
       <ul>
           <li v-for="item in list" :key="item.id">
               <button @click="goDetail(item.id)">
                    {{item.name}}
                </button> 
           </li>
       </ul>
    </template>
    <script>
        export default {
            data(){
                return{
                    list:[]
                }
            },
            created(){
                this.getData(this.$route.params.type); //$route 才有params 动态路由。
            },
            methods:{
                goDetail(id){
                    this.$router.push({name:'detail',params:{id:id}})  //哪里需要detail页面哪里就可以 $router的才能push detail。
                },
                getData(type){
                    this.$http.get('http://localhost:3000/'+type).then((res)=>{
                        this.list = res.data;
                    }) 
                }
            },
            watch:{
                $route(new,old){
                    this.getData(new.params.type); //所有再实例上挂载的属性都可以进行监听
                }
            }
        }
    </script>
  • 相关阅读:
    @hdu
    @51nod
    @51nod
    @51nod
    JS-正则表达式常规运用
    CSS-复选框默认样式修改
    Vue-路由传参query与params
    Vue-阻止页面回退
    Vue-表单提交
    JS-原生的ajax
  • 原文地址:https://www.cnblogs.com/l8l8/p/9391982.html
Copyright © 2011-2022 走看看