@ccos/webos-vue
Version:
A Web-Ui Framework for Skyworth/Coocaa TV
77 lines (76 loc) • 2.55 kB
JavaScript
import { ref, computed, openBlock, createElementBlock, createElementVNode, toDisplayString, normalizeClass, nextTick, pushScopeId, popScopeId } from "vue";
import "./index39.mjs";
import _export_sfc from "./index34.mjs";
const _withScopeId = (n) => (pushScopeId("data-v-eb2824ea"), n = n(), popScopeId(), n);
const _hoisted_1 = { class: "m-switch-wrap" };
const _hoisted_2 = { class: "switch-inner" };
const _hoisted_3 = ["checked", "true-value", "false-value"];
const _hoisted_4 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ createElementVNode("span", { class: "d-switch_action" }, null, -1));
const _sfc_main = {
__name: "switch",
props: {
modelValue: {
//绑定值
type: [Number, String, Boolean]
},
activeValue: {
//switch 打开时的值 可以自定义组件打开的时的值
type: [Number, String, Boolean],
default: true
},
inactiveValue: {
// switch 关闭时的值 可以自定义组件关闭的时的值
type: [Number, String, Boolean],
default: false
},
text: {
type: String,
default: ""
},
disabled: {
type: Boolean,
default: false
}
},
emits: ["update:modelValue", "change"],
setup(__props, { emit: __emit }) {
const props = __props;
const emits = __emit;
const input = ref(null);
const checked = computed(() => {
return props.modelValue === props.activeValue;
});
const handleInput = () => {
nextTick(() => {
const val = input.value.checked;
console.log("val=====>", val);
emits("update:modelValue", val);
emits("change", val);
});
};
return (_ctx, _cache) => {
return openBlock(), createElementBlock("div", _hoisted_1, [
createElementVNode("div", _hoisted_2, toDisplayString(__props.text), 1),
createElementVNode("div", {
class: normalizeClass(["d-switch", { "is-checked": checked.value, " disabled": __props.disabled }])
}, [
createElementVNode("input", {
class: "d-switch__input",
ref_key: "input",
ref: input,
type: "checkbox",
checked: checked.value,
onChange: handleInput,
"true-value": __props.activeValue,
"false-value": __props.inactiveValue
}, null, 40, _hoisted_3),
_hoisted_4
], 2)
]);
};
}
};
const TvSwitch = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-eb2824ea"]]);
export {
TvSwitch as default
};