Sending arguments to a component without using quotation marks

Staying safe and staying productive at home with some coding!

I've been working on creating a customized component for personal use that is essentially integrating the functionalities of the UI Kit framework when it comes to buttons.

Here's the code snippet:

BaseButton.vue

<template>
  <button v-if="!modal" :class="start + bType + bSize + displayBlock" :disabled="disable">
    <span v-show="icon !== ''" :uk-icon="'icon: ' + icon"></span> <slot></slot>
  </button>
  <a v-else :class="start + bType + bSize + displayBlock" :disabled="disable" href="#base-modal" uk-toggle>
    <span v-show="icon !== ''" :uk-icon="'icon: ' + icon"></span> <slot></slot>
  </a>
</template>

<script>
export default {
  props: {
    type: {
      type: String,
      default: "",
    },
    size: {
      type: String,
      default: "",
    },
    icon: {
      type: String,
      default: "",
    },

    disable: {
      type: Boolean,
      default: false,
    },

    block: {
      type: Boolean,
      default: false,
    },

    modal: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      start: "uk-button",
      displayBlock: this.block === true ? " uk-width-1-1" : "",
      bType:
        this.type === "" ? " uk-button-default " : " uk-button-" + this.type,
      bSize: this.size === "" ? "" : " uk-button-" + this.size,
    };
  },
};
</script>

App.vue

<tg-btn :block="true" :type="'primary'" :size="'large'" :icon="'cog'">Test button</tg-btn>

Currently, I can only pass string props by using double quotes and then single quotes around the string. This method is not very time-efficient for me, so I am looking for a solution to simplify this process. Specifically, I would like to address the following questions:

  • Is there a way to pass strings without having to use double quotes twice, like this:

<tg-btn :block="true" :type="primary" :size="large" :icon="cog">Test button</tg-btn>

  • Additionally, is there a way to achieve something like the following example? If so, what technology should I explore:

<tg-btn block large primary icon="trash">Test button</tg-btn>

Thank you for your assistance! Stay safe and happy coding!

Best regards, T.

Answer №1

When dealing with certain attributes, it may be necessary to remove the binding indicator :. Additionally, for attributes that are boolean values, you can leave them without a value if the value is true:

<custom-btn disabled block size="large" icon="cog">Click me</custom-btn>

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

Find a specific value within a complex array of objects in Angular 2

Recently delving into Angular 2, I am seeking guidance on the best approach for a particular use-case. My array of Objects is structured as follows: users : Array<Object> = [{ id: 1, tags: [{ name: 'foo', age: 21 ...

Resizing Elements with JQuery and Moving Them Forward

I have successfully made multiple objects draggable and resizable using the JQuery plugins for Draggable and Resizable. While dragging an object, it automatically comes to the front due to the stack option. However, when resizing an element without draggin ...

"Encountering a 400 Error While Attempting to Edit Requests in NodeJS/A

Currently, I am building an application using Ionic/Angular with a NodeJS backend. Within this project, I have created an update form that allows users to modify or delete a specific row. While the deletion function is working fine, I am facing some challe ...

How can you center popup windows launched from the main window using jquery?

Within my web application, I frequently utilize popup windows that open at different locations on the screen. These popups are standard windows created with window.open() rather than using Jquery. Now, I am seeking a solution to automatically center all p ...

Anchor no longer follows endpoint after Anchor ID is modified following creation - JSPlumb

I am currently developing an editor that involves placing shapes on a canvas and assigning IDs to them. When a shape is placed, endpoints are automatically created and attached to the shape using its ID as an anchor. //Function responsible for adding en ...

Exploring the possibilities of infinite scroll in JavaScript using the Backbone framework

I've been grappling with this problem for three days straight. I've been attempting to incorporate scrolling into my backbone project using the https://github.com/paulirish/infinite-scroll plugin. Despite my best efforts to find a solution throu ...

Submitting Forms with XMLHttpRequest

I'm trying to utilize XMLHttpRequest in order to retrieve the response from a remote PHP file and showcase it on my webpage. The issue I'm facing is that the form's data isn't being submitted to the remote PHP page. Any suggestions on ...

Using a CSS style to modify a class based on another class at the same level in the hierarchy

I am working with a jQuery carousel that is adding an 'active' class to images within a div. Within the same div, there is also a span with a 'fade' class that has a CSS style of opacity: 0. Is there a way to change the CSS style of the ...

Tips for sending a slack message as a workspace user with the chat.postmessage method

I've developed a slack bot with interactive buttons. Once a user clicks a button, I want to send a direct message to that user, displaying their profile image instead of the bot's profile image. I'm currently using the Slack API method chat. ...

Enhance text search functionality using AngularJS

Just starting to learn angularjs. Below is the code I've written: $scope.styles = [{"name":"walking"},{"name":"Food"},{"name":"culture"}] I have created a checkbox list <div ng-repeat="style in styles"> <input type="checkbox"> {{ ...

What is the best way to create an arrow connecting a parent div to multiple child divs?

I'm faced with a challenge involving a reusable React list component that supports nested children. My goal is to visually connect the parent div to its direct children using arrows, similar to the image linked below. View List Component Image Below ...

Issue: mongoose.model is not a valid function

I've been diving into several MEAN tutorials, and I've hit a snag that none of them seem to address. I keep encountering this error message: Uncaught TypeError: mongoose.model is not a function Even after removing node_modules and reinstalling ...

Highcharts Maps - Circular zoom controls

Currently implementing the Highcharts API for a special project. All features are functioning well except for one issue. I am looking to make the zoom in/out buttons appear rounded. I have attempted using border-radius with 50%, as well as modifying the r ...

Prepending a string to the value using Angular's ngOptions

I've been working on creating a custom directive for Angular that includes a label and select element with necessary classes. This is what my directive code looks like: return { restrict: 'E', scope: { text: &a ...

Double request being sent by Ajax

Sample URL: Note: Please use the test sign in credentials: test/test for username/password. I am currently working on an AJAX request to fetch data from a database. The serverTime.php file appears to be functioning correctly as it is inserting and return ...

Dynamically remove values from other fields in a React Formik form based on checkbox conditions

Currently, I am utilizing react-formik for my form implementation. I have encountered an issue with checkbox-based conditions where the checked status of a checkbox determines whether two hidden fields are displayed or hidden. If the user checks the checkb ...

Stuck with the Same Theme in the AppBar of material-UI?

Currently, I am attempting to modify the theme of a material-UI AppBar by utilizing states. Strangely enough, although the icons are changing, the theme itself is not. If you'd like to take a look at the code, you can find it here: https://codesandbo ...

Node.js accepts JSON data sent via XMLHttpRequest

I have successfully implemented a post method using xmlhttprequest: var xhttp = new XMLHttpRequest() xhttp.onreadystatechange = function () { if (this.readyState === 4 && this.status === 200) { console.log('Request finished. Pro ...

Show only a cropped section of a resized image within a div

I have a script that calculates the best region of an image to display within a specific div size. This calculation is done in PHP and generates a JSON output like this: {"scale":1.34,"x1":502,"x2":822,"y1":178,"y2":578} The image in question has dimensi ...

Problem encountered when using the Mongoose find() method with the exec() function

Could you please clarify why the code snippet below is returning audiences instead of an empty array? return Audience.find() .exec((err, audiences) => { if (err) return errorHandler.handle('audienceService', err); return Promise.re ...