美文网首页
加载vue.js的几种方法

加载vue.js的几种方法

作者: 夜凉听风雨 | 来源:发表于2022-03-24 13:53 被阅读0次

一、直接链接加载

直接从vue的服务器请求下来,缺点是可能会受到源服务器的速度影响,会比较慢。
<script src="https://unpkg.com/vue/dist/vue.js"></script>

二、本地资源加载

已经放在本地文件夹里了
<script type="text/javascript" src="./node_modules/vue/dist/vue.js"></script>

三、模板加载

image.png

下面是app.vue文件的代码:
它作为一个组件,使用的export来将自己导出

<template>
    <div id="app">
        <Mycomponent ref="child" @myEvent="mine" :parentParams="params">
        </Mycomponent>
        <button @click="clickMethod"></button>
    </div>
</template>
<script></script>
<script>
    import Mycomponent from './components/MyComponent.vue'

    export default {
        name: 'App',
        data() {
            return {
                params: "哈哈哈"
            }
        },
        components: {
            Mycomponent
        },
        mounted() {

        },
        methods: {
            mine(a) {
                console.log('调用父模块方法' + a)
            },
            clickMethod() {
                console.log(this.$refs['child'].age)
            }
        }

    }
</script>

<style>
    #app {
        font-family: Avenir, Helvetica, Arial, sans-serif;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-align: center;
        color: #2c3e50;
        margin-top: 60px;
    }
    
    p {
        color: #42B983;
    }
</style>

相关文章

网友评论

      本文标题:加载vue.js的几种方法

      本文链接:https://www.haomeiwen.com/subject/oxirdltx.html