No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Shorthand notation for conditional attributes (Solved)

    Help
    2
    4
    112
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • mboeni
      mboeni last edited by mboeni

      Hi there

      I am using this snippet of code:

      <div v-for="message in messages" v-bind:key="message.id">
        <div v-if="message.from === 'Michael'">
          <q-chat-message
            :name="message.from"
            :text="[message.text]"
            sent
          />
        </div>
        <div v-else>
          <q-chat-message
            :name="message.from"
            :text="[message.text]"
          />
        </div>
      

      and immediately felt my solution is not really elegant. I am replicating a lot of code for one single attribute (sent). Is there a more elegant way to do a conditional check for an attribute (in this case for sent in q-chat-message?

      Cheers,
      M.

      1 Reply Last reply Reply Quote 0
      • s.molinari
        s.molinari last edited by s.molinari

        If I understand what your issue is, try this.

            <q-chat-message
              :name="message.from"
              :text="[message.text]"
              :sent="message.from === 'Michael'"
            />
          </div>
          <div v-else>
            <q-chat-message
              :name="message.from"
              :text="[message.text]"
            />
          </div>
        
        

        Scott

        mboeni 1 Reply Last reply Reply Quote 0
        • mboeni
          mboeni @s.molinari last edited by

          @s-molinari

          Yep, thatโ€™s what I was looking for ๐Ÿ™‚

          Actually, all you need is this part:

          <q-chat-message
             :name="message.from"
             :text="[message.text]"
             :sent="message.from === 'Michael'"
          />
          

          Cheers,
          Michael

          1 Reply Last reply Reply Quote 0
          • s.molinari
            s.molinari last edited by

            Naturally. It was late yesterday evening. ๐Ÿ˜Š

            Scott

            1 Reply Last reply Reply Quote 0
            • First post
              Last post