Home > Article > Web Front-end > The difference between href and :href in vue
The difference between href and :href in Vue lies in the data binding method: href: static binding, directly assigning the string address. :href: Dynamic binding, using Vue expressions to bind responsive data or calculated properties to achieve dynamic updates.
The difference between href and :href in Vue
In Vue, href
and The :href
attribute is used to set the address of a hyperlink in an HTML element. The main difference between these two properties is how the data is bound.
href attribute:
href
attribute . :href attribute:
##Specific differences:
href | :href | |
---|---|---|
static | dynamic | |
Not responsive | Responsive (v-bind abbreviation) | |
Set static link | Set dynamic or responsive link |
When to use:
Example:
The following example uses the:href attribute to dynamically set the address of a hyperlink:
<code class="html"><template> <div> <a :href="computedUrl">{{ urlText }}</a> </div> </template> <script> export default { data() { return { urlText: 'Google', }; }, computed: { computedUrl() { return 'https://' + this.urlText + '.com'; }, }, }; </script></code>In In this case, when the
urlText data attribute changes, the hyperlink's address will be automatically updated.
The above is the detailed content of The difference between href and :href in vue. For more information, please follow other related articles on the PHP Chinese website!