源代码:
下载代码
AI 编程工具
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Vue 测试实例 - 菜鸟教程(runoob.com)</title> <script src="https://cdn.staticfile.net/vue/3.2.31/vue.global.min.js"></script> </head> <body> <div id = "app"></div> <script type = "text/javascript"> // 定义混入对象 const myMixin = { created() { this.hello() }, methods: { hello() { document.write('欢迎来到混入实例-RUNOOB!') } } } // 定义一个应用,使用混入 const app = Vue.createApp({ mixins: [myMixin] }) app.mount('#app') // => "欢迎来到混入实例-RUNOOB!" </script> </body> </html>
运行结果: