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

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.

主站蜘蛛池模板: 元氏县| 沅江市| 达日县| 廊坊市| 鹤壁市| 梁山县| 桂平市| 富民县| 东海县| 南陵县| 金门县| 抚州市| 阜南县| 长垣县| 大田县| 波密县| 大安市| 淮南市| 嘉定区| 鹤岗市| 邯郸县| 青铜峡市| 棋牌| 孝义市| 泗洪县| 闽侯县| 当涂县| 宜阳县| 武陟县| 浦县| 丰镇市| 保亭| 涟源市| 安阳市| 无棣县| 西藏| 广州市| 罗源县| 麻栗坡县| 汤阴县| 当雄县|