In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the knowledge of "how to define component templates in Vue". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
String form
Vue is the simplest and most straightforward way to define component templates, but the way it is written is unfriendly, just like we used to concatenate HTML elements, which is very painful, so we don't use it very often.
Vue.component ("my-button", {data: function () {return {label: "cut me if you are a brother"}, template: "{{label}"})
Template literal quantity
Template literal ES6 syntax, unlike strings, we can write multiple lines, which has a great advantage over simple strings, and the experience is better, but there may be problems with browser compatibility and need to be translated into ES5 syntax.
Vue.component ("my-content", {data: function () {return {label: "cut me if you are a brother", content: "knife attack"}}, template: `{{label}} {{content}}`})
Inline template (inline-template)
The "X-template" template definition method is called an alternative to the template definition, which defines the content inside the component tag element rather than distributing it as slot content, which is more flexible, but allows us to separate the template of the component from other attributes.
{{label}} Vue.component ('my-label', {data: function () {return {label: "get in the car, bro die"}})
X-template
Define a tag, mark the text/x-template type, and link through id.
{{label}} Vue.component ('my-label', {template: "# label-template", data: function () {return {label: "get in the car, brother die"})
Rendering function
Rendering functions require the full programming capabilities of JavaScript and are closer to compilation than templates, but we need to be very familiar with the instance properties of Vue and be more abstract. Instructions like v-if v-for can be easily implemented using JavaScript syntax.
Vue.component ('my-label', {data: function () {return {items: [' on arrival!' ,'I'll send it when I come!' , 'send it when you come!'] }, render: function (createElement) {if (this.items.length) {return createElement ('ul', this.items.map (function (item) {return createElement (' li', item)})} else {return createElement ('activity ends')}})
JSX
Compared with the abstraction of rendering functions, JSX is easier and more friendly to students who are familiar with React.
Vue.component ('my-label', {data: function () {return {label: ["activity ends"]}}, render () {return {this.label})
Single file component
Using the build tool cli to create a project, taken together, single file components should be the best way to define components without the additional cost of learning template syntax.
{{item}} export default {data () {return {items: ["I cut", "I cut"]};}}; "how to define component templates in Vue" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.