html页面引入vue组件之http-vue-loader.js

首先这种方法不推荐,日常工作中也不会在html里面引入一个vue文件,只是为了有时候方便测试才会这么做

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>

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>

这样就可以直接在html页面里面引用vue文件,而不需要从头开始创建一个新的vue项目,方便日常测试使用

httpVueLoader的其他组件载入方式可查看这里

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值