anchor-link2.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var anchorLink = require('./anchor-link.js');
  5. var constants = require('./constants.js');
  6. var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
  7. const __default__ = vue.defineComponent({
  8. name: "ElAnchorLink"
  9. });
  10. const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  11. ...__default__,
  12. props: anchorLink.anchorLinkProps,
  13. setup(__props) {
  14. const props = __props;
  15. const linkRef = vue.ref(null);
  16. const {
  17. ns,
  18. direction,
  19. currentAnchor,
  20. addLink,
  21. removeLink,
  22. handleClick: contextHandleClick
  23. } = vue.inject(constants.anchorKey);
  24. const cls = vue.computed(() => [
  25. ns.e("link"),
  26. ns.is("active", currentAnchor.value === props.href)
  27. ]);
  28. const handleClick = (e) => {
  29. contextHandleClick(e, props.href);
  30. };
  31. vue.watch(() => props.href, (val, oldVal) => {
  32. vue.nextTick(() => {
  33. if (oldVal)
  34. removeLink(oldVal);
  35. if (val) {
  36. addLink({
  37. href: val,
  38. el: linkRef.value
  39. });
  40. }
  41. });
  42. });
  43. vue.onMounted(() => {
  44. const { href } = props;
  45. if (href) {
  46. addLink({
  47. href,
  48. el: linkRef.value
  49. });
  50. }
  51. });
  52. vue.onBeforeUnmount(() => {
  53. const { href } = props;
  54. if (href) {
  55. removeLink(href);
  56. }
  57. });
  58. return (_ctx, _cache) => {
  59. return vue.openBlock(), vue.createElementBlock("div", {
  60. class: vue.normalizeClass(vue.unref(ns).e("item"))
  61. }, [
  62. vue.createElementVNode("a", {
  63. ref_key: "linkRef",
  64. ref: linkRef,
  65. class: vue.normalizeClass(vue.unref(cls)),
  66. href: _ctx.href,
  67. onClick: handleClick
  68. }, [
  69. vue.renderSlot(_ctx.$slots, "default", {}, () => [
  70. vue.createTextVNode(vue.toDisplayString(_ctx.title), 1)
  71. ])
  72. ], 10, ["href"]),
  73. _ctx.$slots["sub-link"] && vue.unref(direction) === "vertical" ? (vue.openBlock(), vue.createElementBlock("div", {
  74. key: 0,
  75. class: vue.normalizeClass(vue.unref(ns).e("list"))
  76. }, [
  77. vue.renderSlot(_ctx.$slots, "sub-link")
  78. ], 2)) : vue.createCommentVNode("v-if", true)
  79. ], 2);
  80. };
  81. }
  82. });
  83. var AnchorLink = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "anchor-link.vue"]]);
  84. exports["default"] = AnchorLink;
  85. //# sourceMappingURL=anchor-link2.js.map