<script src="./js/jquery.js"></script> <script src="./js/axios.js"></script> <script src="./js/libs/jquery-validation-1.14.0/jquery.validate.js"></script> <script src="./js/libs/layer/layer.js"></script> <script src="./js/libs/md5.js"></script> <script src="./js/reg.js"></script>以上这段在vue里怎么写
时间: 2023-07-02 18:04:45 浏览: 436
vue中axios.js
在Vue中,我们可以使用`import`语句来引入外部的库和文件,然后在Vue组件中使用它们。假设你的这些JS文件都在`/src/assets/js`目录下,那么你可以这样写:
```javascript
<script>
import $ from '@/assets/js/jquery.js'
import axios from '@/assets/js/axios.js'
import 'jquery-validation' // 因为没有默认导出,所以不需要起别名
import layer from '@/assets/js/libs/layer/layer.js'
import md5 from '@/assets/js/libs/md5.js'
import reg from '@/assets/js/reg.js'
export default {
// 组件内容
}
</script>
```
然后,在Vue组件中,你可以使用这些引入的库和文件了,例如:
```javascript
methods: {
submitForm() {
if ($('#my-form').validate().form()) {
axios.post('/api/register', {
username: this.username,
password: md5(this.password)
}).then(response => {
layer.msg('注册成功!')
}).catch(error => {
layer.msg('注册失败!')
})
}
}
}
```
阅读全文