这似乎应该是一个简单的解决方案,但出了点问题......
我需要有条件地从元素中删除 contenteditable
属性:
<!-- first state -->
<div contenteditable="true"></div>
<!-- second state -->
<div></div>
我试过了:
data() {
return {
contenteditable: true,
title: "Title",
};
},
methods: {
handleClick() {
this.contenteditable = null;
this.title = null;
},
},
render(createElement) {
const options = {
attrs: {
id: "ID",
title: this.title,
contenteditable: this.contenteditable,
// Not working either
//...(this.contenteditable && { contenteditable: true }),
},
domProps: {
innerHTML: "<p>Test</p>",
},
on: {
click: this.handleClick,
},
};
return createElement("div", options);
},
结果是:<div contenteditable="false"></div>
,但我需要完全删除属性。例如title
,属性按预期工作,如果它的值设置为 null,它不会呈现。我还尝试使attrs
对象完全反应,例如:
data() {
return {
attrs: {
title: 'Title',
contenteditable: true,
}
}
},
methods: {
handleClick() {
Vue.delete(this.attrs, 'contenteditable')
Vue.delete(this.attrs, 'title')
},
},
render(createElement) {
const options = {
attrs: this.attrs,
domProps: {
innerHTML: "<p>Test</p>",
},
on: {
click: this.handleClick,
},
};
return createElement("div", options);
},
...但没有运气。任何想法如何解决这个问题?
谢谢!