美文网首页首页推荐
vue2.0踩坑之旅

vue2.0踩坑之旅

作者: 子龙爱弹琴 | 来源:发表于2016-11-24 11:45 被阅读45次

初入vuejs,描述一些踩坑经历

  • methods方法不能使用es6的写法来实现
data: {
   name: "子龙",
   newName: "xiaohei" 
},
methods: {
    changeName: () => {
      console.log(2222);
      this.name = '小红';
      this.newName = '小白';
    }
  }

这样写的话,会发现数据不会发生变化,即不会触发双向绑定的事件的发生,更加严重的是,要是我们使用的是单文件的组件方式的话,会直接对应不到相应的数据

<script>
module.exports = {
  name: 'app',
  data () {
    return {
      items: [1,2,3,4],
      nextNum: 4
    }
  },
  methods: {
    randomIndex: () => {
      return Math.floor(Math.random()*this.items.length);
    },
    add: () => {
      this.items.splice(this.randomIndex(), 0, ++this.nextNum);
    },
    remove:  () => {
      this.items.splice(this.randomIndex(), 1);
    }
  }
}
截图 2016-11-24 11时16分14秒.jpg

目前还没有找到具体的问题所在,可能是webpack打包的时候有点问题,所以建议在写methods方法的时候使用最基本的方法格式,即:

data: {
   name: "子龙",
   newName: "xiaohei" 
},
methods: {
    changeName: function () {
      console.log(2222);
      this.name = '小红';
      this.newName = '小白';
    }
  }

相关文章

  • vue2.0踩坑之旅

    初入vuejs,描述一些踩坑经历 methods方法不能使用es6的写法来实现 这样写的话,会发现数据不会发生变化...

  • Vue2.0踩坑

    Tips 1.命名规范: 一是不使用非法的标签字符;二是不与 HTML 元素(区分大小写)或 SVG 元素(不区分...

  • RecyclerView ItemTouchHelper 拖动排

    RecyclerView ItemTouchHelper 踩坑之旅 要实现的功能: recyclerview it...

  • 踩坑之旅

    > db.user.update({"parentuser":"wyt1314"},{$set:{"parentu...

  • 踩坑之旅

    1.启动项目报错org.springframework.beans.factory.UnsatisfiedDepe...

  • 高仿饿了么app项目

    在制作项目的时候踩的坑 1、vue2.0不支持挂载 2、stylus与stylus-loader安装版本为最新版 ...

  • 踩坑之旅ing

    EventBus接入 最近在接eventbus,遇到Could not find subscriber metho...

  • error 踩坑之旅

    报错图如下: 正常报错原因:数据源与操作tableView insert 、delete数量不一致狐友用的另外一个...

  • vux 踩坑之旅

    1 点击事件不触发 类似以下这种 2 x-input is-type= china-mobile china-n...

  • Flutter踩坑之旅

    记录下自己踩过的坑,怕忘了 一.TextField: 1.去掉输入数字的计数:decoration中的counte...

网友评论

    本文标题:vue2.0踩坑之旅

    本文链接:https://www.haomeiwen.com/subject/csjbpttx.html