the reviewer's identity is private. Once this is working I will add v-if-else"> Conditional rendering in Vue: Show only if Firestore field value matches a specific string value-PHP Chinese Network Q&A
Conditional rendering in Vue: Show only if Firestore field value matches a specific string value
P粉007288593
P粉007288593 2023-08-28 18:48:23
0
2
430

Firestore database fields (reviewPrivacy fields in the "review" collection) are of type string, populated by Vue form inputs (radio buttons), with three possible answers (values) One is keepFullyPrivate.

If the value of review.reviewPrivacy is keepFullyPrivate, I want to show that

the reviewer's identity is private< /h2>.

Once this is working, I will add the v-if-else and v-else options to display different content for each option.

My code is as follows.

No errors are flagged in VSC, but the text in the

tag always appears no matter what the value of review.reviewPrivacy , regardless of whether it is equal to keepFullyPrivate.

Commenter's identity is private

Update (additional information):

  • I am using Vue 3.2.1 version
  • The data obtained from Firestore is correct. For example, in the same parent as the code above, this line of code

    Privacy choices for this review: {{ review.reviewPrivacy }}

    in the DOM Display the following text: Privacy choices for this comment: postAnonPublic, which is a v-else-if condition.

Second update: As requested in the comments, make the code a complete block:

Privacy choices for this review: {{ review.reviewPrivacy }}


The reviewer's identity is private

Anonymous - Reviewer: {{ review.userName }}

Reviewer chose full disclosure - full name {{ review.userFirstName }} {{ review.userLastName }}


Created {{ review.createdAt }} days ago


Thank you!

P粉007288593
P粉007288593

reply all (2)
P粉864872812

new Vue({ el: "#app", data: { review: { reviewPrivacy:0 }, keepFullyPrivate:0 } })
 

评论者的身份是私密的

其他部分

    P粉265724930

    ('review.reviewPrivacy', '==', 'keepFullyPrivate')is just a set of comma-separated strings, and its value is the last string:'keepFullyPrivate ', so your tag becomesv-if="'keepFullyPrivate'", which is always true. Therefore,divand itsh2will always be rendered.

    The correct expression to comparereview.reviewPrivacyand'keepFullyPrivate'is:

    review.reviewPrivacy == 'keepFullyPrivate' // 或者更好的写法: review.reviewPrivacy === 'keepFullyPrivate'

    It is a good practice to use three equal signs (====) forstrict comparison.

    Therefore, the final result should be:

    评论者的身份是私密的

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!