[英]How to make a sample that shows the 'Props are overwritten when re-rendering' anti pattern
我想確信“重新渲染時 Props 被覆蓋”是一種反模式。
const MyButton = Vue.extend({
props: {
obj: {}
},
template:
"<button @click=\"obj.text = 'Value'+Math.round(Math.random()*100)\">Change text in child ({{obj.text}})</button>"
});
const app = new Vue({
el: "#main",
data: {
obj: { text: "Value2" }
},
components: {
MyButton
},
template: `
<div>
<Button @click='obj.text = "Value"+Math.round(Math.random()*100)'>Change text in parent ({{obj.text}})</Button><br>
<MyButton :obj='obj'/> 👈 Pressing here 'mutate' the prop. It is an anti-pattern (Props are overwritten when re-rendering). But it seems to work just fine, how to change this sample so it shows the anti-pattern problem? (https://eslint.vuejs.org/rules/no-mutating-props.html)
</div>`
});
更新代碼筆: https://codepen.io/SVSMITH/pen/LYrXRzW
誰能幫忙?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.