源代码 :
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Vue 测试实例 - 开源教程(ossoft.cn)</title> <script src="https://unpkg.com/vue@next"></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>
运行结果