学习vue中遇到的一些注意事项

1、注册事件  .native

    <my-component v-on:click.native="doTheThing"></my-component>

2、修改prop的数据

 定义一个局部变量,并用prop的值初始化它。

    props: ['initialCounter'],

    data: function ({

        return {  counterthis.initialCounter }
    }
    定义一个计算属性,处理 prop 的值并返回:

    props: ['size'],

    computed: {

        normalizedSize: function ({

            return  this.size.trim().toLowerCase()
    }
}

3、遍历的数组值更新了,值也赋值了,为什么视图不更新?

this.$set(obj,item,value)

var vm = new Vue({

data: {
userProfile: {
name:  'Anika'
}
}
})
你可以添加一个新的  age  属性到嵌套的  userProfile  对象:
 
    
Vue.set(vm.userProfile,  'age'27)

对已有对象赋值多个新属性

 
    
this.userProfile = Object.assign({}, this.userProfile, {
age: 27,
favoriteColor: 'Vue Green'
})

4、v-for循环 加上key 否则会报红

<div v-for="item in items" :key="item.id">

<!-- 内容 -->
</div>
5、 vue-router实现登录和跳转到指定页面,vue-router传参
定义路由的时候可以配置 meta 字段
const router = new VueRouter({
  routes: [
    {
      path: '/foo',
      component: Foo,
      children: [
        {
          path: 'bar',
          component: Bar,
          // a meta field
          meta: { requiresAuth: true }
        }
      ]
    }
  ]
})
6.vue事件冒泡问题
    
<div class="signList" @click.stop>
7.动画
    
:style="{transform: 'rotate(' + 360 / imgArr.length * index + 'deg)'}"
document.querySelector('.train-station dt').style.transform = `rotate(${this.count}deg)`  



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值