官术网_书友最值得收藏!

Creating Vue components

Now we're confident our code is cleaner, we can move on to making Vue components for the various parts of our app. Put aside your code for now and open a new document while you get to grips with components.

Vue components are extremely powerful and a great addition to any Vue app. They allow you to make packages of reusable code that include their own data, methods, and computed values.

For our app, we have the opportunity to create two components: one for each person and one for the filtering section of our app. I would encourage you to always look at breaking your app into components where possible—this helps group your code into related functions.

Components look like mini Vue instances as each one has its own data, methods, and computed objects—along with some component-specific options that we will cover shortly. Components are also extremely useful when it comes to creating an app with different pages and sections—this will be covered in Chapter 8Introducing Vue-Router and Loading URL-Based Components

When a component is registered, you create a custom HTML element to use in your view, for example:

      <my-component></my-component>

When naming your component, you can use kebab-case (hyphens), PascalCase (no punctuation, but each word is capitalized) or camelCase (similar to Pascal but the first word is not capitalized). Vue components are not restricted by, or associated with, the W3C web components/custom element rules, but it is good practice to follow this convention of using kebab-case.

主站蜘蛛池模板: 新乐市| 宜昌市| 桓台县| 北票市| 深水埗区| 松原市| 安阳县| 宁化县| 沾化县| 闽侯县| 化州市| 沾化县| 广宗县| 乌鲁木齐市| 阿瓦提县| 延安市| 绥阳县| 合江县| 婺源县| 十堰市| 黎平县| 高淳县| 广平县| 元谋县| 鹤岗市| 汕尾市| 延长县| 泊头市| 娄底市| 黄龙县| 沧源| 淮北市| 蕲春县| 兴义市| 嘉黎县| 麻城市| 古丈县| 商丘市| 双峰县| 新乡市| 莆田市|