Files
EdgeAdmin/web/public/js/components/common/checkbox.js

36 lines
901 B
JavaScript
Raw Normal View History

2020-11-18 15:41:29 +08:00
let checkboxId = 0
Vue.component("checkbox", {
2021-01-11 18:15:53 +08:00
props: ["name", "value", "v-value", "id", "checked"],
2020-11-18 15:41:29 +08:00
data: function () {
checkboxId++
let elementId = this.id
if (elementId == null) {
elementId = "checkbox" + checkboxId
}
let elementValue = this.vValue
if (elementValue == null) {
elementValue = "1"
}
2021-01-11 18:15:53 +08:00
let checkedValue = this.value
if (checkedValue == null && this.checked == "checked") {
checkedValue = elementValue
}
2020-11-18 15:41:29 +08:00
return {
elementId: elementId,
elementValue: elementValue,
2021-01-11 18:15:53 +08:00
newValue: checkedValue
2020-11-18 15:41:29 +08:00
}
},
methods: {
change: function () {
this.$emit("input", this.newValue)
}
},
template: `<div class="ui checkbox">
<input type="checkbox" :name="name" :value="elementValue" :id="elementId" @change="change" v-model="newValue"/>
2020-12-23 16:49:53 +08:00
<label :for="elementId" style="font-size: 0.85em!important;"><slot></slot></label>
2020-11-18 15:41:29 +08:00
</div>`
})