继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

html中引入vue组件,2步解决

幕布斯7119047
关注TA
已关注
手记 432
粉丝 28
获赞 99

    今天给大家说一说关于html中引入vue组件的方法,希望对各位前端小伙伴所有帮助,具体如下:

    html页面引入vue组件需要在页面引入http-vue-loader.js

1,创建my-component.vue

<template>
   <div class="hello">Hello {{who}}</div>
</template>

<script>
module.exports = {
   data: function() {
       return {
           who: 'world'
       }
   }
}
</script>

<style>
.hello {
   background-color: #ffe;
}
</style>12345678910111213141516171819

2,创建index.html

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 先引入 Vue -->
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <!-- 引入 http-vue-loader -->
    <script src="https://unpkg.com/http-vue-loader"></script>
</head>

<body>
    <div id="app">
        <my-component></my-component>
    </div>
</body>

<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
    // 使用httpVueLoader
    Vue.use(httpVueLoader);
    new Vue({
        el: '#app',
        data: function () {
            return { visible: false }
        },
        components: {
            // 将组建加入组建库
            'my-component': 'url:./component/my-component.vue'
        }
    })
</script>

</html>

    注意:要查看页面引入vue组件的效果不能直接在本地打开index.html,会有跨域问题,可以在本地配置一个nginx转发,再用浏览器访问http://localhost:port/index.html

    以上就是关于html中引入vue组件的全部内容,更多内容干货可以关注慕课网~

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP