前端 cdn 方式使用 Vue + element-ui

该文介绍了如何在网页中引入Vue.js和Element-UI库,首先通过unpkgCDN加载,然后检查window对象,如果未定义则使用本地备份的js文件,确保库的正常加载。接着展示了创建Vue实例的基本步骤,并提供了在body中使用Vue的模板结构。
摘要由CSDN通过智能技术生成

一、引入资源

// 引入vue
<script src="https://unpkg.com/vue@2.7.10/dist/vue.min.js"></script>
<script>window.Vue || document.write(unescape("%3Cscript src='../static/js/vue-2.7.10.min.js' type='text/javascript'%3E%3C/script%3E"))</script>
// 引入element-ui
<script src="https://unpkg.com/element-ui@2.15.13/lib/index.js"></script>
<script>window.ELEMENT || document.write(unescape("%3Cscript src='../static/js/element-ui-2.15.13-index.js' type='text/javascript'%3E%3C/script%3E"))</script>

// 上面的原理是先导入 unpkg 的cdn 包,如果没有 window.Vue 或者 window.ELEMENT 则使用本地的。
// 必须替换unescape中的"<" 和 ">", %3C = <, %3E = >。

二、创建 vue 对象

<script>
    app = new Vue({
        el: '#app',
        data() {
            return {}
        },
        methods:{}
    });
</script>

三、使用

<body>
    <div id="app">
        <template>
            <!-- html -->
        </template>
    </div>
</body>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值