隨便寫一個js文件,定義一個方法名,並且在組件中進行引用就算成功
###~js
function shuchu(){
console.log(1)
}
export { shuchu };
###~.vue
<template>
<div class="hello">
<button @click="gettwo()">點擊</button>
</div>
</template>
<script>
import {shuchu} from '../assets/get'
export default {
data () {
return {
}
},
methods: {
gettwo(){
shuchu();
}
},
}
</script>
現在點擊就會控制台出現一個1啦
放上參考網站: