vue 引入自定义css 和js
一. 引入自定义js
方法一
首先在main.js中引入:
import Comjs from \'./js/common.js\' //引入公用js
Vue.prototype.$comjs = Comjs; //添加到vue属性中
自定义js 中写:
const comjs = {
}
comjs. = function ( ) {
alert( )
}
export default comjs;
页面中使用:
<template>
<div>
<button class=\"btn\" @click=\"clickme\">click me</button>
</div>
</template>
< >
export default {
data(){
return{
}
},
methods:{
clickme(){
this.$comjs. (\'你点我了\');
}
}
}
</ >
2.方法二(此方法不需要在main.js中引入)
自定义js 中写:
function (t){
alert(t);
}
export {
//多个方法在此处json中export出去
}
页面中使用:
<template>
<div>
<button class=\"btn\" @click=\"clickme\">click me</button>
</div>
</template>
< >
import { } from \'./js/common.js\' //可以选择需要的方法引入
export default {
data(){
return{
}
},
methods:{
clickme(){
(\'你点我了\');
}
}
}
</ >
二. 引入自定义css
在main.js中引入公用css
import \'../static/css/common.css\' //引入公用css
在页面中引入单独css
<style scoped>
@import \'../../static/css/header.css\';
</style>
---------------------
作者:桃夭蓁蓁
来源:CSDN
原文:https://blog.csdn.net/liuxing393724034/article/details/80775065
版权声明:本文为博主原创文章,转载请附上博文链接!
继续阅读与本文标签相同的文章
上一篇 :
云场景实践研究第89期:中信集团
下一篇 :
centos7安装MYSQL
-
斩获2019中国金融科技创新大赛金奖,蚂蚁金服mPaaS助力打造超级App生态
2026-05-19栏目: 教程
-
有呀!互联网icp许可证除申请以外有转让的吗?飞起
2026-05-19栏目: 教程
-
Apache Zepplin使用Hive Interpreter查询
2026-05-19栏目: 教程
-
大宗货运如何实现“重去重回”?
2026-05-19栏目: 教程
-
企业官网怎么选择合适的阿里云服务器ECS(新手参考)
2026-05-19栏目: 教程
