vue中data的值改变不了

我在created中alert的name值和long值都是正确的,为什么在chose中name的值就是undefined,而且在created中改变了的long和short值为true,在页面中还是false

            <li v-bind:class={active:long}  @click='chose'>
                <router-link to='/long'>第一页{{long}}</router-link>
            </li>
            <li v-bind:class={active:short}>
                <router-link to='/short'>第二页{{short}}</router-link>

            </li>
            

不管传过来的name是什么值,页面中的long和short都是false

 import Vue from 'vue';
    export default  {
      props: ['name'],
      data() {
            return {             
                long:false,
                short:false,

            }
        },
        methods:{

            chose(){
                console.log(this.name);//这里输出undefined
                console.log(this.short);
            }

        },
        created(){
           var name=this.name;
           console.log(name);//这里值是正确的
           switch (name){
              case "long":
                   this.long=true;
                   alert(that.long+"long");//当name值为long时弹出true
                   break;
               case "short":
                   alert(name);
                   this.short=true;
                   break;
              
           }
        },


    }
阅读 3.3k
1 个回答

你这代码看着逻辑很混乱,点击事件里面有页面跳转。that还没有看见你定义,this.shop也没见到,一步步认真检查下。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题