vite-plugin-mockjs-yu
v1.0.4
Published
mockjs-utils with vite
Downloads
5
Maintainers
Readme
vite-plugin-dns-prefetch
a mockjs util with vite
install
npm install vite-plugin-yu-mockJS -D
Usage
export default defineConfig({
plugins: [ mockJS({
root_url: './mock',
prefix:'/api'
})],
})
define a dir that store mockjs data,eg: src/mock/user/user.json user.json->
{
"data":{
"name": "测试",
"age": 18
},
"message":"测试信息",
"status":200
}
defaultOptions
{
prefix: '/api', // mockJS will find the begin with prefix
root_url: './src/mock',//mockJS will find json in the directory
}
// example:
const xhr = new XMLHttpRequest()
xhr.open('GET', '/api/user')
xhr.onreadystatechange = function () {
if (xhr.readyState == 4)
console.log(xhr.responseText, 'res')
}
xhr.send()