小编zhe*_*era的帖子

更新 vue 中的 props 值

vue中如何通过方法更新props值?所以我的 props 宽度默认值为 20

<div :style="{ width: width+ 'px'}">
Run Code Online (Sandbox Code Playgroud)
props: {
  width: {
    type: [String, Number],
    default: '20px'
  },
}
Run Code Online (Sandbox Code Playgroud)

然后它会将组件渲染为 width=20px。我可以使用 javascript 更改 props 值吗?例如它可能看起来像这样(?)

myEventHandler(e) {
  if(window.innerWidth < 768 && this.width === '20')
  this.width = '' // I want to revert the value to empty like it never used this props before. But I get vue warn that the prop being mutated
},
Run Code Online (Sandbox Code Playgroud)

任何帮助都会非常有帮助,谢谢!

javascript vue.js vuejs2

0
推荐指数
1
解决办法
6039
查看次数

标签 统计

javascript ×1

vue.js ×1

vuejs2 ×1