This commit is contained in:
zhaoxinyu
2024-11-28 17:25:39 +08:00
parent ad1b4e1e71
commit 60c4e355b4
5 changed files with 740 additions and 0 deletions
@@ -0,0 +1,23 @@
Vue.mixin({
mounted() {
if (this.$options.style) {
const styleId = `style-${this._uid}`
const style = document.createElement("style")
style.id = styleId
//支持函数和字符串
const css = typeof this.$options.style === "function" ? this.$options.style.call(this) : this.$options.style
style.textContent = css
document.head.appendChild(style)
}
},
beforeDestroy() {
if (this.$options.style) {
const styleId = `style-${this._uid}`
const style = document.getElementById(styleId)
if (style) {
document.head.removeChild(style)
}
}
}
})