{"id":13446,"date":"2025-09-11T07:11:20","date_gmt":"2025-09-11T07:11:20","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/qanda\/?p=13446"},"modified":"2025-09-11T07:11:20","modified_gmt":"2025-09-11T07:11:20","slug":"add-jquery-to-vue-cli-3","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/qanda\/vue\/add-jquery-to-vue-cli-3","title":{"rendered":"Add jQuery to Vue CLI 3"},"content":{"rendered":"<p>Here\u2019s how you can add <strong>jQuery to a Vue CLI 3 project.<\/strong><\/p>\n<h2>1. Install jQuery<\/h2>\n<p>Use npm to install jQuery into the project:<\/p>\n<pre class=\"lang:adddarkplain\">npm install jquery<\/pre>\n<h2>2. Add jQuery to Global Scope<\/h2>\n<p>Update or create vue.config.js in the root directory of the project. Add webpack.ProvidePlugin to inject jQuery globally so it\u2019s accessible throughout the project without needing to import it each time.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"r\">\r\n\/\/ vue.config.js\r\nconst webpack = require('webpack');\r\n\r\nmodule.exports = {\r\n configureWebpack: {\r\n   plugins: [\r\n     new webpack.ProvidePlugin({\r\n       $: 'jquery',\r\n       jQuery: 'jquery'\r\n     })\r\n   ]\r\n }\r\n};<\/pre>\n<h2>3. Use jQuery in Vue Components<\/h2>\n<p>You can now directly use jQuery selectors and methods inside the methods or lifecycle hooks of Vue components.<br \/>\n<strong>For example:<\/strong><\/p>\n<pre class=\"lang:adddarkplain\">&lt;!-- ExampleComponent.vue --&gt;\r\n&lt;template&gt;\r\n &lt;div&gt;\r\n   &lt;button @click=\"highlightText\"&gt;Click Me&lt;\/button&gt;\r\n   &lt;p class=\"text\"&gt;Hello from jQuery&lt;\/p&gt;\r\n &lt;\/div&gt;\r\n&lt;\/template&gt;\r\n&lt;script&gt;\r\nexport default {\r\n methods: {\r\n   highlightText() {\r\n     $('.text').css('color', 'red');\r\n   }\r\n }\r\n};\r\n&lt;\/script&gt;<\/pre>\n<h3>Notes<\/h3>\n<ul>\n<li>Ensure you restart the development server after editing vue.config.js.<\/li>\n<li>This setup is ideal for adding legacy jQuery functionality or plugins inside a Vue 2 (CLI 3) project.<\/li>\n<\/ul>\n<div class=\"qanda-read-box\"><div class=\"bg-light read-more-icon\"><img decoding=\"async\" src=\"https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/04\/24061434\/read-txt.png\" alt=\"Also Read\"><p><\/p><h3>Also Read:<\/h3><a href=\"https:\/\/www.bacancytechnology.com\/blog\/vue-js-authentication-and-authorization\" target=\"_blank\">Vue js Authentication and Authorization<\/a><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Here\u2019s how you can add jQuery to a Vue CLI 3 project. 1. Install jQuery Use npm to install jQuery into the project: npm install jquery 2. Add jQuery to Global Scope Update or create vue.config.js in the root directory of the project. Add webpack.ProvidePlugin to inject jQuery globally so it\u2019s accessible throughout the project [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":13447,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[13],"tags":[],"class_list":["post-13446","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vue"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/13446"}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/comments?post=13446"}],"version-history":[{"count":1,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/13446\/revisions"}],"predecessor-version":[{"id":13448,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/13446\/revisions\/13448"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media\/13447"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media?parent=13446"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/categories?post=13446"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/tags?post=13446"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}