Using attributes in components
Attributes in a component allow it to pass parameters for its use. For example, we could use in the <counter>
component a start
attribute indicating at what value we start counting. If this attribute is not indicated, it is considered to be 0 (that is, counting starts at 0 as in the preceding code example).
For a component to be able to employ attributes during its use, it suffices to indicate the name of the attributes in the props
section of the component. The component can access the attribute value using the this
keyword (for example, this.start
to access the start
attribute in the component). We can see this in action in the following code:
Using the start attribute in the component (index.html file)
<html> <head> <meta charset="utf-8" /> <script src="https://unpkg.com/vue@next"></script> </head> ...