Skip to content

how to use it in vue.js with vue.directive #73

Open
@Mirocos

Description

@Mirocos

I want use it in vue with its directive with hightlightjs, how to use it?

Vue.directive('highlightjs', {
  deep: true,
  bind: function(el, binding) {
    // on first bind, highlight all targets
    let targets = el.querySelectorAll('code')
    targets.forEach((target) => {
      // if a value is directly assigned to the directive, use this
      // instead of the element content.
      if (binding.value) {
        target.textContent = binding.value
        console.log(target)
      }
      hljs.highlightBlock(target)
      // hljs.lineNumbersBlock(target)
    })
  },
  componentUpdated: function(el, binding) {
    // after an update, re-fill the content and then highlight
    let targets = el.querySelectorAll('code')
    targets.forEach((target) => {
      if (binding.value) {
        target.textContent = binding.value
        // hljs.initLineNumbersOnLoad();
        hljs.highlightBlock(target)

        // hljs.lineNumbersBlock(target)
      }
    })
  }
})

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions