Use of @
Background: When you encounter @ function during the operation of the vue project, the scene is special (the project has a component library that is encapsulated by itself, so all styles are integrated uniformly. When you want to introduce special UI style processing in special cases, some components need to re-tune the style, so @ is used).
What is the function of @?
Note: @ is a built-in function of vue. There are many other functions in vue that also have rich application scenarios. This blog post has been thinking about it over and over again, and only explains @. For understanding other functions, you can check the relevant information by yourself.
Solution: The @ function will block the original event that triggers the dom and execute a specific event.
To better understand the @ function, a sample of usage in a project is introduced for reference:
<!-- Sample --> // Codding... <a class="img-control" v-show="true" @="goXxxx()">Revise</a> <!-- Analysis: aThe tag has its own by defaulthrefproperty,triggeraAfter tagging, it will automatically jump to the corresponding link address or executed function.。 For nesting here,Avoid adjusting styles so referencedaTags to handle,But to avoida标签的property限制,Therefore, the quote@Function blocking default operations。 (I would like to give some additional instructions here,But there are not many cases to explain it well,Update later,Only here at this moment) -->
vue also has several commonly used functions, such as: @(enter carriage return event), etc.
@and@
@
Problem: A click event was added to the parent element, and the click event was also added to the child element below. At this time, I want to click the child element to get the click event of the child element, but it triggers the event of the parent element:
<view class="footer-box" @click="clickCard"> <view @click="footerClick('like')"><text class="footer-box__item">like</text></view> <view @click="footerClick('Comment')"><text class="footer-box__item">Comment</text></view> <view @click="footerClick('share')"><text class="footer-box__item">share</text></view> </view>
At this point, we need to use the @:Stop event bubble method to solve this problem:
<view class="footer-box" @click="clickCard"> <view @="footerClick('like')"><text class="footer-box__item">like</text></view> <view @="footerClick('Comment')"><text class="footer-box__item">Comment</text></view> <view @="footerClick('share')"><text class="footer-box__item">share</text></view> </view>
@
There is also a similar method: @: Block the default behavior of events, for example: Write a tag in the code, click it and jump to the target link web page:
<view class="example-body"> <a href="" rel="external nofollow" rel="external nofollow" >Baidu</a> </view>
But if we don't want it to jump but still want to use the a tag, we need to use the @ method at this time:
<view class="example-body"> <a href="" rel="external nofollow" rel="external nofollow" @='notLink'>Baidu</a> </view>
When you click on the a tag, the target address link will not be redirected.
The above is personal experience. I hope you can give you a reference and I hope you can support me more.