babu-ch / vue3-v-html-link-handler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vue3 v-html link handler

replace the link in v-html with router.push

https://www.npmjs.com/package/vue3-v-html-link-handler

Usage

npm i vue3-v-html-link-handler

const html = "<p><a href="/relative">relative</a></p>" +  # router.push
             "<p><a href="https://example.com">relative</a></p>" # open new tab

<VHtmlLinkHandler :html="html"/>

Props

const props = defineProps({
   // v-html value
   html: {
      type: String,
      required: false,
      default: "",
   },
   // tag. default is div
   tag: {
      type: String,
      required: false,
      default: "div",
   },
   // Callback called before navigating with router.push
   // move only if true
   beforeMoveInternalCallBack: {
      type: Function,
      required: false,
   },
   // Callback invoked before navigating outside
   // move only if true
   beforeMoveExternalCallBack: {
      type: Function,
      required: false,
   },
   // check target=_blank internal link
   checkBlankInternalLink: {
      type: Boolean,
      required: false,
      default: false,
   },
   // check target=_blank external link
   checkBlankExternalLink: {
      type: Boolean,
      required: false,
      default: false,
   }
})

emit

const emits = defineEmits<{
  // Always emit when navigating to a link
  (e: "afterMove", href: String): void
  // Always emit when navigating to an internal link
  (e: "afterMoveInternal", href: String): void
  // Always emit when navigating to an external link
  (e: "afterMoveExternal", href: String): void
}>()

develop

pnpm install

pnpm dev

pnpm build

pnpm test

Vue 3 + TypeScript + Vite

This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 <script setup> SFCs, check out the script setup docs to learn more.

Recommended IDE Setup

Type Support For .vue Imports in TS

TypeScript cannot handle type information for .vue imports by default, so we replace the tsc CLI with vue-tsc for type checking. In editors, we need TypeScript Vue Plugin (Volar) to make the TypeScript language service aware of .vue types.

If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a Take Over Mode that is more performant. You can enable it by the following steps:

  1. Disable the built-in TypeScript Extension
    1. Run Extensions: Show Built-in Extensions from VSCode's command palette
    2. Find TypeScript and JavaScript Language Features, right click and select Disable (Workspace)
  2. Reload the VSCode window by running Developer: Reload Window from the command palette.

About


Languages

Language:TypeScript 56.2%Language:Vue 32.3%Language:CSS 9.4%Language:HTML 2.1%