How to have Vue.js recognize Pug in a String template? Example:
Vue.component('my-component', {
template: `
div
div`})
I saw how this can be done in standalone templates, as in:
<template lang='pug'>
div
div
</template>
But I would like to be able to use pug in String templates.
Most backend developers choose to use Pug with Vue. js because it's much easier to implement and read and doesn't require a whole lot of configuration. Any valid HTML is also a valid Vue.
js, also known as PUG, is a Javascript library that was previously known as JADE. It is an easy-to-code template engine used to code HTML in a more readable fashion. One upside to PUG is that it equips developers to code reusable HTML documents by pulling data dynamically from the API.
Vue uses an HTML-based template syntax that allows you to declaratively bind the rendered DOM to the underlying component instance's data. All Vue templates are syntactically valid HTML that can be parsed by spec-compliant browsers and HTML parsers.
We use pug in our vue templates using x-template, here's a shell component:
script(type="text/x-template" id="admin-tags")
div
h1 Admin Tags
script.
var AdminTags = Vue.component('admin-tags', {
template: "#admin-tags",
props: ["options"],
data: function(){
return {
}
}
});
Then we just include the files with the components in the parent template. It works really well.
UPDATE 04/2019: I have recently started a new project using vue-cli and vue-cli-plugin-pug has been working very well. It's as easy as this:
<template lang='pug'>
div
h1 Home
ul
li A
li B
li C
</template>
<script>
export default {
name: 'Home',
data () {
return {
}
}
}
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With