hongluan-ui
Version:
Hongluan Component Library for Vue 3
66 lines (63 loc) • 2.1 kB
JavaScript
import { defineComponent, getCurrentInstance, ref, inject, onMounted, openBlock, createElementBlock, normalizeClass, renderSlot, createCommentVNode, createElementVNode } from 'vue';
import '../../../hooks/index.mjs';
import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
const _sfc_main = defineComponent({
name: "ListItem",
props: {
type: String,
to: {
type: [String, Object],
default: ""
},
replace: {
type: Boolean,
default: false
}
},
emits: ["select-item"],
setup(props) {
const { namespace } = useNamespace("list-item");
const instance = getCurrentInstance();
const router = instance.appContext.config.globalProperties.$router;
const listItemRef = ref(null);
const { selectItem } = inject("ListComponnetContext");
onMounted(() => {
listItemRef.value.addEventListener("click", (evt) => {
selectItem(evt);
if (!props.to || !router)
return;
props.replace ? router.replace(props.to) : router.push(props.to);
});
});
return {
namespace,
listItemRef
};
}
});
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createElementBlock("div", {
ref: "listItemRef",
class: normalizeClass([_ctx.namespace, _ctx.type ? _ctx.type : ""])
}, [
_ctx.$slots.prefix ? (openBlock(), createElementBlock("span", {
key: 0,
class: "item-prefix"
}, [
renderSlot(_ctx.$slots, "prefix")
])) : createCommentVNode("v-if", true),
createElementVNode("span", { class: "item-content" }, [
renderSlot(_ctx.$slots, "default")
]),
_ctx.$slots.suffix ? (openBlock(), createElementBlock("span", {
key: 1,
class: "item-suffix"
}, [
renderSlot(_ctx.$slots, "suffix")
])) : createCommentVNode("v-if", true)
], 2);
}
var ListItem = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
export { ListItem as default };
//# sourceMappingURL=list-item.mjs.map