Guide on how to include jquery-ui css file in Vue3

I am new to TypeScript and VueJs. Recently, I decided to incorporate jquery-ui into my project using Vue3, TypeScript, and Electron.

After some trial and error, I was able to successfully set up the environment. However, when I attempted to use the jquery-ui resizable API, I encountered an issue with importing the required CSS file. Despite researching methods for importing CSS files in Vue components using Vue and webpack, I found multiple approaches which left me confused.

One of the articles I referred to was:

  • import jQuery-ui and jQuery with npm install

My code snippet looks like this:

import $ from "jquery";
import "jquery-ui";

import 'jquery-ui/themes/base/theme.css'  // <== encountering error here
import 'node_modules/jquery-ui/xxx-theme.css'  // <== this also doesn't work
@import "~jquery-ui-dist/jquery-ui.theme.css"; // <== this works, but has no effect 

Prior to this, I followed the configuration steps outlined in the following site Using jQuery UI in a Vue.js x TypeScript Project:

// install jquery, jquery-ui and typescript one
$ npm install jquery jquery-ui --save
$ npm install @types/jquery @types/jqueryui --save-dev

// tsconfig.json
{
  "compilerOptions": {
    ...
    "paths": {
      "@/*": [
        "src/*"
      ],
      "jquery-ui": [
        "node_modules/@types/jqueryui/index"
      ]
    },
    ...
  • install jquery-ui-dist
$ npm install jquery-ui-dist --save

// vue.config.js
const path = require("path");
module.exports = {
  configureWebpack: {
    devtool: "source-map",
    optimization: {
      minimize: false
    },
    resolve: {
      alias: {
        // bind version of jquery-ui
        "jquery-ui": "jquery-ui-dist/jquery-ui.js",
        // bind to modules;
        modules: path.join(__dirname, "node_modules")
      }
    }
  }
};

Answer №1

After some trial and error, I finally figured out how to successfully load css files using the following steps.

  • To start, I added the "jquery-ui-css" alias in my vue.config.js file. This allowed Vue to import css using import "jquery-ui-css";
resolve: {
  alias: {
    // reference: https://github.com/jzaefferer/webpack-jquery-ui#using-resolvealias-to-simplify-imports
    // linking jquery-ui version
    "jquery-ui": "jquery-ui-dist/jquery-ui.js",
    "jquery-ui-css": "jquery-ui-dist/jquery-ui.css",
    // linking modules;
    modules: path.join(__dirname, "node_modules")
  }
},
  • Next, in the vue component, I imported the necessary modules.
<script lang="ts">
import $ from "jquery";
import "jquery-ui";
import "jquery-ui-css";

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

How can I make v-for display additional profiles to achieve an infinite scroll effect?

Hey there! I've got a Firestore database set up to fetch profiles and display them on a page using v-for. I want to implement infinite scroll for a smoother user experience. Here's the JavaScript composable code I'm working with: import { pr ...

In which part of the DOM tree are Event/Callbacks typically located?

As I work on creating a one-page web application, the task of dynamically constructing nested Backbone.View components arises. My typical approach involves building an empty jQuery object, populating it with div elements, binding events to it, and then re ...

Error: React - Unable to access the 'lazy' property because it is undefined

I used a helpful guide on the webpack website to incorporate TypeScript into my existing React App. However, upon launching the app, an error message pops up saying: TypeError: Cannot read property 'lazy' of undefined The version of React being ...

Trouble with updating data in Angular 8 table

In Angular 8, I have created a table using angular material and AWS Lambda as the backend. The table includes a multi-select dropdown where users can choose values and click on a "Generate" button to add a new row with a timestamp and selected values displ ...

Utilize jQuery to deactivate all click interactions except for the scrollbar

I am currently working on creating a page that is completely unclickable, both with right and left clicks, and I want to display a message when someone attempts to click. This may lead to some questions such as "Why would anyone want to do this? This s ...

Converting a string value into an object in Javascript using a command that functions similarly to eval in Python

When working with Python, the stringValue variable is often assigned as a string: stringValue = '{"DATA":{"VERSION":1.1, "STATE":True, "STATUS":"ONLINE"}}' To convert this string into a Python di ...

Vue fails to trigger a rerender of the list, even when the set function is utilized

I created a list where each item can be removed, and this is how my code looked: Snippet <template v-for="(timeFrame, index) in form.timeFrames"> <el-form-item > ...

What is the best way to add an Apple iPhone-like effect to a menu list?

I've been working on creating a menu similar to the Apple menu using the greensock api Here is my progress so far: JSFIDDLE Update This is what I am aiming for: Fiddle Any idea why there is flickering when hovering over it? <div class="de ...

What is the most efficient way to access a cell within an HTML table using jQuery or the Document Object Model (

I have an unchangeable HTML table styled with CSS. My goal is to extract the value from the first column for filtering purposes. I've been struggling to locate a suitable jQuery or DOM function to accomplish this task. Unable to find a way to access ...

Large background images on websites often appear pixelated

Check out my website: I've noticed that the background image appears blurry on my screen, despite its size being 1920 x 1080 px. I've tried using a jquery script to manage this background issue as all of the CSS methods have provided unsatisfact ...

Issue: Multiplying values within an array in TypeScript requires that the left-hand side of the arithmetic operation must be of type 'any', 'number', or 'enum'

Having trouble with Typescript as I encounter this error message The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.ts(2362) Specifically facing issues when trying to multi ...

`The best way to access a JavaScript variable from PHP`

This is the code snippet I am working on: var daaa=document.getElementById('da').value= year+ "-" +month+ "-" +day; document.form1.bookingsession.focus(); var coords = { "lat": daaa }; $.get('bs.php', coords, function () { ...

Support different response types when making nested API calls

When working with two API calls that return different responses, one typed as TestData1Res and the other as TestData2Res, how can I handle the scenario where the response could be either type and process the property? `TestData1Res{ testData: string } Te ...

React approach for managing multiple combobox values

Currently, I'm working on a page where users can upload multiple files and then select the file type for each file from a dropdown menu before submitting. These 'reports' are the uploaded files that are displayed in rows, allowing users to c ...

Angular 2's ng-required directive is used to specify that

I have created a model-driven form in Angular 2, and I need one of the input fields to only show up if a specific checkbox is unchecked. I was able to achieve this using *ngIf directive. Now, my question is how can I make that input field required only whe ...

Transfer data between an HTML page and a PHP page hosted on separate locations using jQuery

Below is the code snippet I am currently working on: function send_data() { var a=$("#username").val(); var b=$("#password").val(); $.post("http://localhost/login/login.php", {uname: a, pswd: b}, function(data) { $("#result").html(data); }); ...

What is the method for obtaining a unique exception message in the ajaxError event of jQuery?

Is there a way to customize the content of responseText in my APP? Currently, it displays as exception description amended by Tomcat (refer to the image below). I want to have control over the content of responseText or handle custom messages in a more eff ...

Retrieve the audio file from the server endpoint and stream it within the Vue application

I am working on a listing module which includes an audio element for each row. I need to fetch mp3/wav files from an API and bind them correctly with the src attribute of the audio element. Below is my code snippet: JS methods:{ playa(recording_file) ...

Issue encountered when sending information to asmx web service via ajax and displaying the result on an HTML page with a javascript function

I have developed an ASMX web service that looks like this: [ScriptService] public class CurrencyData : System.Web.Services.WebService { [WebMethod] public string DisplayCurrency(double amount, string sign ,string style) { swi ...

Enriching HtmlElement with a type property using TypeScript

Check out my TypeScript code snippet below: let script: HTMLElement = document.createElement("script"); script.appendChild(document.createTextNode(` { "json": "property" } `)); script.id = 'appContextModel'; document.body.appendChild(scr ...