+1 vote
in VueJS by
What are the problems solved by Single File Components?

1 Answer

0 votes
by

The Single File Components solve the common problems occurred in a javascript driven application with a .vue extension. The list of issues are,

Global definitions force unique names for every component

String templates lack syntax highlighting and require ugly slashes for multiline HTML

No CSS support means that while HTML and JavaScript are modularized into components, CSS is conspicuously left out

No build step restricts us to HTML and ES5 JavaScript, rather than preprocessors like Pug (formerly Jade) and Babel

What are filters?

Filters can be used to apply common text formatting. These Filters should be appended to the end of the JavaScript expression, denoted by the “pipe” symbol. You can use them in two specific cases:

mustache interpolations

v-bind expressions

For example, Let's define a local filter named capitalize in a component’s options

filters: {

  capitalize: function (value) {

    if (!value) return ''

    value = value.toString()

    return value.charAt(0).toUpperCase() + value.slice(1)

  }

}

Now you can use the filter in either mustache interpolation or v-bind expression,

<!-- in mustaches -->

{{ username | capitalize }}

<!-- in v-bind -->

<div v-bind:id="username | capitalize"></div>

...