In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
How to quote js from vuejs? for this question, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a simpler and easier way.
The method that vuejs references js: 1. Introduce jquery;2 globally through vue-cli webpack, reference external js;3 through "import {myfun} from'.. / js/test.js'" method, and reference internal js in a single vue page. This article operating environment: Windows7 system, vue2.9.6 version, DELL G3 computer.
How does vuejs reference js?
Multiple ways for vue to reference js files (recommended)
1. Vue-cli webpack introduces jquery globally.
(1) first npm install jquery-- save (--save means to install the module into the project directory and write dependencies in the dependencies node of the package file.)
(2) add to webpack.base.conf.js
Var webpack = require ("webpack")
(3) add at the end of module.exports
Plugins: [new webpack.optimize.CommonsChunkPlugin ('common.js'), new webpack.ProvidePlugin ({jQuery: "jquery", $: "jquery"})]
(4) ok is introduced in main.js (you don't have to test this step)
Import $from 'jquery'
(5) then npm run dev can use $directly in the page.
The project structure is shown in the figure:
Content component code:
Click
Import {myfun} from'. / js/test.js' / / Note the path export default {data () {return {testvalue:''}}, methods: {diyfun:function () {myfun ();}
Test.js Code:
Function myfun () {console.log ('Success')} export {/ / critical myfun}
3. A single vue page refers to the internal js method
(1) first npm install jquery-- save (--save means to install the module into the project directory and write dependencies in the dependencies node of the package file.)
(2) introduce $in the vue page to be referenced by import, and then use it.
There is a yellow warning in this picture. If you change console.log ($) to this:
Export default {mounted: function () {console.log ($)}}
There will not be, probably because it has to conform to the way js is written in vue.
This is the answer to the question about how vuejs quotes js. I hope the above content can be of some help to you. If you still have a lot of doubts to solve, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.