1. 新建methods.js
export function alertMessage(txt) { alert(txt) }
2. 组件中引入并使用
<template> <div> <button @click="alertMessage(111)">弹窗</button> </div> </template> <script> import {alertMessage} from "../../assets/js/methods"; export default { data() { return { alertMessage } } } <script>