Vue3 v-html link handler
replace the link in v-html with router.push
Usage
# simple
<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
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
- VS Code + Volar (and disable Vetur) + TypeScript Vue Plugin (Volar).
.vue
Imports in TS
Type Support For 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:
- Disable the built-in TypeScript Extension
- Run
Extensions: Show Built-in Extensions
from VSCode's command palette - Find
TypeScript and JavaScript Language Features
, right click and selectDisable (Workspace)
- Run
- Reload the VSCode window by running
Developer: Reload Window
from the command palette.