-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to use it in vue.js with vue.directive #73
Comments
I haven't experience in vue.js, but found some solution for you in vue-highlightjs package: https://github.com/metachris/vue-highlightjs/blob/master/index.js#L8 To continue will be the same as highlightjs, Usage - initialization: https://github.com/wcoder/highlightjs-line-numbers.js#usage |
|
but the format is invalid! |
@xiaodun 这个问题你找到解决的办法了吗?遇到相同的问题了,求告知,谢谢 |
I import highlight.js and highlightjs-line-numbers.js in index.html. Then use following code to initialize: hljs.initHighlightingOnLoad();
hljs.initLineNumbersOnLoad(); when it comes to update the highlight code and just use following code to re-render it: this.code = hljs.highlightAuto(this.shader.vs).value; // in my case , this.shader.vs is the target code
hljs.initLineNumbersOnLoad(); The html code is here: <pre ><code v-html="code">
</code></pre> |
I try it ,but failed o(╥﹏╥)o , Thanks all the way |
where did you initialize the format? |
i have solved this problem, and i've recorded it in my blog https://www.zhoujianguo.ltd/#/fore/article?id=140 |
My Vue3 + TypeScript + "vue-plugin-load-script" package solution: import * as vue from 'vue'
import hljs from "highlight.js";
import {loadScript} from "vue-plugin-load-script";
const codeStr = vue.ref("")
vue.onBeforeMount(async () => {
// codeStr.value = "..."
await vue.nextTick();
(window as any).hljs = hljs;
loadScript("https://cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/2.8.0/highlightjs-line-numbers.min.js").then(() => {
(window as any).hljs.initLineNumbersOnLoad();
})
}) <template>
<div>
<highlightjs :code="codeStr" />
</div>
</template> |
I want use it in vue with its directive with hightlightjs, how to use it?
The text was updated successfully, but these errors were encountered: