What is the best way to include an SVG in a ternary operation?

I have a complex custom input with autocomplete functionality as part of the customization. To maintain confidentiality, I will only share the snippet of code related to the suggestion drop-down in the autocomplete feature. I have two values - suggestions and searchHistory - based on the user's cached search history. To distinguish between the two, I want to display either a clock icon or an SVG image. While I can render an emoji, it doesn't align with my design theme, so I'm looking to use a clock SVG from my library.

How can I include this SVG in the ternary operator? I've seen examples of people using '<img :src="..something"/>', but that syntax doesn't work for me.

Any suggestions on how I can achieve this?

Cheers!

CAutocompleteList.vue

<template>
  <ul>
    <li
      v-for="suggestion in filteredSuggestions"
      :key="suggestion"
      @click="$emit('selectSuggestion', suggestion)"
    >
      {{ suggestion }} {{ searchHistory.includes(suggestion) ? '⏱' : '' }}
    </li>
  </ul>
  <!-- <IconPowerSupplyOne theme="outline" size="100%" fill="#4771FA" /> -->
</template>

<script lang="ts">
import { defineComponent, PropType } from 'vue'

export default defineComponent({
  props: {
    filteredSuggestions: { type: Array as PropType<string[]>, required: true },
    searchHistory: { type: Array as PropType<string[]>, required: true },
  },
  emits: ['selectSuggestion'],
  setup() {
    return {}
  },
})
</script>

Answer №1

It is not recommended to use a ternary operator in this scenario due to the limitations with text interpolation and HTML elements.

Instead, it is advisable to utilize the v-if directive:

<svg v-if="searchHistory.includes(suggestion)">
  ...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Adjust the size of the password input characters without changing the appearance of the placeholder

Is there a way to enlarge the font size of an HTML password input without changing the placeholder text as well? Specifically, I am looking to increase the size of the password symbols (bullets). I attempted to adjust the font-size property of input[type= ...

What is the best way to retrieve a JSON string in JavaScript after making a jQuery AJAX request?

Why am I only seeing {} in the console log when ajax calling my user.php file? $.ajax({ url: '.../models/user.php', type: 'POST', dataType: "json", data: {username: username, password:password, func:func}, succ ...

Mongoose Troubles in NodeJS

I am reaching out to seek assistance with a problem I am facing that I have been unable to resolve on my own. My tech stack includes nodejs, express, and mongodb (particularly using mongoose). Although my express server is running smoothly, I am encounter ...

In ReactJS, the import module.fucntion is functioning properly, however, when attempting to import { function } from '../../module', it is not working as

Encountering import issues, specifically when using the following code: import module from '../../module' console.log(module.func) The function is printed as expected. However, when trying this approach: import { func } from '../../module&a ...

Using ReactJS and react-router to exclude the navigation menu on the login page

I have a LoginPage designed like this: https://i.sstatic.net/yzovV.png After logging in, you will be directed to this page: https://i.sstatic.net/pZFou.png Now, I want the login page to have no navigation and look like this: https://i.sstatic.net/1sH9v ...

Exploring FileReader and DOMParser for AngularJS applications

I have a user uploaded file using AngularJS and would like to manipulate the file contents using XML. Unfortunately, I am facing an issue with the DOMParser recognizing the text file. index.html <div ng-controller = "myCtrl"> <input type ...

Trouble retrieving data (React-redux)

Greetings! I am currently working on a project involving the Spotify API and attempting to retrieve new releases. While the data is successfully passed down to the reducer, I encounter an issue when calling the fetch action in my App component. When I try ...

Despite element being a grandchild, the function this.wrapperRef.current.contains(element) will return false

The issue arises when using the EditModal component with an onClickOutside event. This component includes a child element, a Material-UI Select, where clicking on a MenuItem triggers the onClickOutside event, causing the modal to close without selecting th ...

AngularJS: Blocking access to specific state for users

I am currently in the process of developing an application using sails.js for the backend and Angular for the frontend. My goal is to restrict access to the admin control page for unauthorized users. I have come across several solutions, but none of them s ...

Swap out flash for javascript

I am embarking on a new task: replacing the flash element with JavaScript on this page: (switching images for buttons for each image) Naturally, it must maintain the same appearance and functionality. I have come across some jQuery modules that achieve s ...

Custom hooks in Next.js do not have access to the localStorage object

I've encountered an issue with my custom useLocalStorage hook. It works perfectly fine with create-react-app, but when I try to use it with Next.js, the value in the initial state on line 3 returns undefined. Is there a way to bypass server-side rend ...

"Authorization refused" notification on Internet Explorer 6

Encountering an error in IE6 on line 10 with this code. Specifically, var ref = ...; What could be causing the issue here? <html> <head> <title>JavaScript Popup Example 3</title> </head> <SCRIPT language="JavaScript1.2"& ...

What is the process for adding a download link to my canvas once I have updated the image?

Is it possible to create a download link for an image that rotates when clicked, and then allows the user to download the updated image? Any help would be appreciated.////////////////////////////////////////////////////////////////////// <!DOCTYPE ht ...

Retrieving information from a separate JavaScript file

I'm currently developing a Discord Bot and my code is all contained within one file. My goal now is to break this code up into multiple files for better organization. For instance, I plan to have: index.js which will handle all the requires (e.g. var ...

A guide on updating the SQL order value through a select option using PHP and jQuery

To modify the arrangement of SQL data according to the chosen select option, I am looking to adjust the ORDER value. Within my action.php file, I retrieve values from the database and aim to incorporate a sorting select option that allows for changing the ...

Issue with Pure Javascript FormData upload involving files and data not successfully processing on PHP end

My file upload form follows the standard structure: <form id="attachform" enctype="multipart/form-data" action="/app/upload.php" method="POST" target="attachments"> <!-- MAX_FILE_SIZE must precede the file input field --> <i ...

javascript accessing an external variable inside ajax function

I have implemented dajaxice to fetch a json attribute that I want to make global. However, I am facing an issue where my global variable is always showing up as "undefined": var recent_id; $(function(){ recent_id = Dajaxice.ticker.get_home_timeline(ge ...

What is the process for obtaining a list of all registered users?

Is there a way to retrieve a list of all the users registered in my course-booking system? Here's the code in my user.js controller: const User = require("../models/User"); const bcrypt = require("bcrypt"); const auth = require(&q ...

AngularJS is failing to update the shared service model

Utilizing AngularJS, my application contains two controllers that share a common service. When triggering an event controlled by the portalController function (specifically the setLang() function), I notice that the model of the applicationController does ...

Caution: The React Hook useEffect is missing a required dependency

What is the best way to eliminate the warning "React Hook useEffect has a missing dependency" while developing my code? Here is a snippet of the code that triggers the warning: useEffect(() => { if(inactive){ document.querySelect ...