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)
任何帮助都会非常有帮助,谢谢!