mixins使用

对于多个vue文件都需要执行的代码,可以放在mixin内,mixin为一个普通对象,属性为需要的data,methods,created等等,如


<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>mixins使用title>
head>
<body>
    <div id="app">

    div>
    <script src="https://cdn.bootcss.com/vue/2.6.8/vue.min.js">script>
    <script>
        let mixinObj = {
            created() {
                console.log(111111)
            }
        }
        new Vue({
            mixins: [mixinObj],
            data() {
                return {
                    msg: 111
                }
            },
            created() {
                console.log(222222)
            }
        })
    script>
body>
html>

你可能感兴趣的:(vue,前端)