vue-html

Use tagged template string in Vue.js render function
3,876 181
Install
npm install vue-html
Latest Version:1.0.0
Vue:2
License:MIT
Last Updated:Dec 25, 2021
Links: GitHub  ·  npm
Maintainer: rem

vue-html

NPM version NPM downloads Build Status

Use tagged template string in Vue.js render function

Why is this useful?

If you want to use Vue without a bundler / transpiler, this library will (reasonably) make your app smaller:

  • Vue (runtime + template compiler): 32kB gzipped
  • Vue (runtime + vue-html): 23kB gzipped

What's the downside? No handy sugars like v-model support.

Install

$ npm install --save vue-html

CDN versions:

Usage

import Vue from 'vue'
import HTML from 'vue-html'

Vue.use(HTML)

const Todos = {
  props: ['todos'],
  render(html) {
    return html`
    <ul>
    ${this.todos.map((todo, index) => {
      return html`<li key=${index}>${todo}</li>`
    })}
    </ul>
    `
  }
}

new Vue({
  el: '#app',
  data: {
    todos: [
      'Conquer the world',
      'Rewrite Peco'
    ],
    todo: ''
  },
  methods: {
    add() {
      this.todos.push(this.todo)
      this.todo = ''
    }
  },
  render(html) {
    return html`
    <div>
      <input value=${this.todo} onInput=${e => this.todo = e.target.value} />
      <button type="button" onClick=${this.add}>Add</button>
      <hr />
      <${Todos} todos=${this.todos} />
    </div>
    `
  }
})

The usage is very similar to Vue JSX except for that the html function is powered by HTM (Hyperscript Tagged Markup).

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT © EGOIST

Related Packages

@processmaker/vue-form-elements

Reusable VueJS Based Form Elements styled with Bootstrap 4

48,893
vue-markup

markdown + support components for Vue.js

17,321 0
html-to-a4-template

Convert html to A4 template, which helps to preview and ensure the print styles

2,475 12
vue-easy-printer

The Best Vue Plugin To convert Html page, Components to pdf

1,717 2
html-validate-vue

vue transform for html-validate

313,416

Version History

Version Released Vue License
1.0.0 ^2.5.21 MIT
0.3.0 latest MIT
0.2.0 latest MIT
0.1.0 latest MIT