声明:实在需要兼容ie的$.ajax,只能在vue的项目里引入jquery
步骤
1.npm引入 jquery
npm i jquery --save
2.如果要引入指定版本
在package.json里添加,然后再npm i
"dependencies": {
"jquery": "^2.1.4",
}
3.在vue.config.js 里添加代码
const webpack = require("webpack");
module.exports = {
configureWebpack: {
....
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"windows.jQuery": "jquery"
})
]
},
....
4.在main.js引用代码
import $ from "jquery"
5.页面直接调用
$.ajax({
type: "post",
url: url,
dataType: "json",
data: