Js judges whether the passed parameter values are equal.

 <image src="../../static/img/point.png" @click="pointClick(items.id)">
 methods: {
   pointClick: function(ID) {
     
   }
 }

how to determine whether the ID value transmitted each time is equal, because it is necessary to ensure that the image after the loop is liked only once, not the second time. Then how can I tell whether the ID value sent each time is the same as the last ID?

Nov.19,2021

pass items past click and add an attribute isClicked=true to judge this attribute


record a global id, compared with this id every time it is clicked.


in fact, you don't need id to capture the event directly and then disable it to the captured object


if there are not many pictures, you can save the clicked id into the array and determine whether the passed id exists in the array the next time you click.


Please take a look at this link. I don't know if it can satisfy your question


you don't usually change the color of the like icon after you like it. This can be associated with whether you can like it or not, and it can be judged by the same status. After giving a like, you can use this.$set () to set a status for the items in the list that have already been liked. In addition, if you have already given likes, don't you have to get them from the background?


take a look at which one you want:

1. If the building owner is to solve the problem of giving likes, then giving likes must be bound to the user. In the click method, you need to call the backend API to determine whether you have given a like.

2. If the landlord just wants to know how to determine whether the passed value already exists, just define a variable in data.


<image src="../../static/img/point.png" @click="pointClick(items)">
 methods: {
   pointClick: function(item) {
     if(item.hasClick) {
        return;
     }
     item.hasClick = true;
     
     //
   }
 }

if you still need to cancel likes or not, which cannot be controlled by the front end, let the backend add a field of whether to like or not.


according to my understanding, 1. Whether to like needs to set a separate field to bind the user's primary key to the background. Otherwise, the like record will be eliminated after reopening the browser or clearing the cache. 2, the page can be based on the previous "like" status to determine whether the picture can be onclick. There is no need to determine whether the id is duplicated.

Menu