当前位置: 首页 > news >正文

html通过CDN引入Vue组件抽出复用

html通过CDN引入Vue组件抽出复用

近期遇到个需求,就是需要在.net MVC的项目中,对已有的项目的首页进行优化,也就是写原生html和js。但是咱是一个写前端的,写html还可以,.net的话,开发也不方便,还得安装Visual Studio启动项目。所以就计划在html文件中开发,然后移植到.net的项目中。

功能说明:需要开发一个dashboard,也就是大屏可视化,多个模块,然后由图表作为主要内容。那么就需要组件封装了,html如何封装组件呢?父组件又如何使用子组件呢?

效果图

在这里插入图片描述
在这里插入图片描述

代码实现

子组件js

var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = './son.css';
document.head.appendChild(link);let htmlstr = `<div><div class="son-box">{{ title }} - {{ content }} - {{str}}</div><div class="echart2">2</div></div>
`// my-component.js
Vue.component('my-component', {props: ['title', 'content'],template: htmlstr,data(){return{str:1}},mounted(){this.initEchart()},methods:{initEchart(){var option = {xAxis: {type: 'category',data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']},yAxis: {type: 'value'},series: [{data: [150, 230, 224, 218, 135, 147, 260],type: 'line'}]};setTimeout(()=>{let chartDom2 = document.getElementsByClassName('echart2')[0]var myChart2 = echarts.init(chartDom2);myChart2.setOption(option);})}}
});

父组件html


<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Vue Grid Layout 示例</title><!-- 引入样式 --><link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"><style>#loader-wrapper { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; z-index: 999999; }#loader {display: block; position: relative; left: 50%; top: 40%; z-index: 1001; width: 90px; height: 90px; margin: -45px 0 0 -45px; border-radius: 50%; border: 3px solid transparent;border-top-color: #fe9501;         -webkit-animation: spin 2s linear infinite;-ms-animation: spin 2s linear infinite;-moz-animation: spin 2s linear infinite;-o-animation: spin 2s linear infinite;animation: spin 2s linear infinite;}#loader:before {content: ""; position: absolute; top: 5px; left: 5px; right: 5px; bottom: 5px; border-radius: 50%; border: 3px solid transparent; border-top-color: #fe9501;-webkit-animation: spin 3s linear infinite;-moz-animation: spin 3s linear infinite;-o-animation: spin 3s linear infinite;-ms-animation: spin 3s linear infinite;animation: spin 3s linear infinite;}#loader:after {content: ""; position: absolute; top: 15px; left: 15px; right: 15px; bottom: 15px; border-radius: 50%; border: 3px solid transparent; border-top-color: #fe9501;-moz-animation: spin 1.5s linear infinite;-o-animation: spin 1.5s linear infinite;-ms-animation: spin 1.5s linear infinite;-webkit-animation: spin 1.5s linear infinite;animation: spin 1.5s linear infinite;}@-webkit-keyframes spin {0% { -webkit-transform: rotate(0deg); -ms-transform: rotate(0deg); transform: rotate(0deg); }100% { -webkit-transform: rotate(360deg); -ms-transform: rotate(360deg); transform: rotate(360deg); }}@keyframes spin {0% { -webkit-transform: rotate(0deg); -ms-transform: rotate(0deg); transform: rotate(0deg); }100% { -webkit-transform: rotate(360deg); -ms-transform: rotate(360deg); transform: rotate(360deg); }}.load-text{color: #fe9501;text-align: center;position: relative;top: 55%;transform: translateY(-50%);}html {font-size: 100%; /*100 ÷ 16 × 100% = 625%*/}@media screen and (min-width:800px) and (max-width:999px) {html { font-size: 65%; }}@media screen and (min-width:1000px) and (max-width:1024px) {html { font-size: 70%; }}@media screen and (min-width:1025px) and (max-width:1280px) {html { font-size: 90%; }}@media screen and (min-width:1281px) and (max-width:1680px) {html { font-size: 100%; }}@media screen and (min-width:1681px) and (max-width:1920px) {html { font-size: 100%; }}@media screen and (min-width:1921px) and (max-width:2240px) {html { font-size: 150%; }}@media screen and (min-width:2241px){html { font-size: 150%; }}.vue-grid-layout {background: #eee;}.vue-grid-item:not(.vue-grid-placeholder) {background: #ccc;border: 1px solid black;}.vue-grid-item .resizing {opacity: 0.9;}.vue-grid-item .static {background: #cce;}.vue-grid-item .text {font-size: 24px;text-align: center;position: absolute;top: 0;bottom: 0;left: 0;right: 0;margin: auto;height: 100%;width: 100%;}.vue-grid-item .no-drag {height: 100%;width: 100%;}.vue-grid-item .minMax {font-size: 12px;}.vue-grid-item .add {cursor: pointer;}.vue-draggable-handle {position: absolute;width: 20px;height: 20px;top: 0;left: 0;background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10'><circle cx='5' cy='5' r='5' fill='#999999'/></svg>") no-repeat;background-position: bottom right;padding: 0 8px 8px 0;background-repeat: no-repeat;background-origin: content-box;box-sizing: border-box;cursor: pointer;}.vue-grid-item{display: flex;}.echart{width: 100%;height: 100%;min-height: 5rem;}</style>
</head>
<body><div id="app"><my-component title="标题" content="我是子组件"></my-component><my-component title="标题" content="我是子组件"></my-component><my-component title="标题" content="我是子组件"></my-component><my-component title="标题" content="我是子组件"></my-component><my-component title="标题" content="我是子组件"></my-component></div><!-- 引入Vue --><script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script><!-- 引入Vuex --><script src="https://unpkg.com/vuex@3.6.2/dist/vuex.js"></script><!-- 引入gird组件 --><script src="./vue-grid-layout.common.js"></script><script src="./vue-grid-layout.umd.min.js"></script><!-- 引入组件库 --><script src="https://unpkg.com/element-ui/lib/index.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.4.3/echarts.min.js"></script><!-- 引入子组件 --><script src="./son.js"></script><!-- 引入vuex --><script src="./store.js"></script><script>new Vue({el: '#app',store,data: {draggable: true,resizable: false,index: 0,visible:false,},mounted(){},methods: {}   });</script>
</body>
</html>

相关文章:

  • 100天精通Python(可视化篇)——第110天:Pyecharts绘制可视化大屏项目(附上完整源码)
  • HttpURLConnection OOM问题记录
  • vr建筑虚拟实景展厅漫游体验更直观全面
  • running小程序重要技术流程文档
  • ubuntu-更改镜像源-系统初始化-安装Clion-C++编译环境-Java安装
  • Nginx的请求速率限制模块的两个关键参数rate和burst和相关代码语句的详细说明。
  • 使用阿里巴巴同步工具DataX实现Mysql与ElasticSearch数据同步
  • Python学习笔记-类
  • neuq-acm预备队训练week 8 P1144 最短路计数
  • VC++使用GetProcessTimes获取进程创建时间、销毁时间、用户态时间、内核态时间
  • 20231207给NanoPC-T4(RK3399)开发板刷Android12的挖掘机方案的LOG
  • Global IIIumination(GI)全局光照原理(一)3D空间全局光照
  • 【计算机网络实验】实验三 IP网络规划与路由设计(头歌)
  • 三. LiDAR和Camera融合的BEV感知算法-BEVFusion实战
  • 聚类算法的性能度量
  • 【编码】-360实习笔试编程题(二)-2016.03.29
  • 【剑指offer】让抽象问题具体化
  • 0基础学习移动端适配
  • 345-反转字符串中的元音字母
  • docker容器内的网络抓包
  • git 常用命令
  • go语言学习初探(一)
  • mysql innodb 索引使用指南
  • Quartz初级教程
  • Spark RDD学习: aggregate函数
  • SpringCloud(第 039 篇)链接Mysql数据库,通过JpaRepository编写数据库访问
  • Xmanager 远程桌面 CentOS 7
  • 基于组件的设计工作流与界面抽象
  • 开年巨制!千人千面回放技术让你“看到”Flutter用户侧问题
  • 如何学习JavaEE,项目又该如何做?
  • 使用Gradle第一次构建Java程序
  • 限制Java线程池运行线程以及等待线程数量的策略
  • 与 ConTeXt MkIV 官方文档的接驳
  • 栈实现走出迷宫(C++)
  • 阿里云服务器购买完整流程
  • ​2020 年大前端技术趋势解读
  • ​埃文科技受邀出席2024 “数据要素×”生态大会​
  • ​业务双活的数据切换思路设计(下)
  • #AngularJS#$sce.trustAsResourceUrl
  • #数据结构 笔记一
  • (~_~)
  • (13)Hive调优——动态分区导致的小文件问题
  • (152)时序收敛--->(02)时序收敛二
  • (4) openssl rsa/pkey(查看私钥、从私钥中提取公钥、查看公钥)
  • (MIT博士)林达华老师-概率模型与计算机视觉”
  • (STM32笔记)九、RCC时钟树与时钟 第一部分
  • (二) 初入MySQL 【数据库管理】
  • (附源码)spring boot北京冬奥会志愿者报名系统 毕业设计 150947
  • (附源码)springboot助农电商系统 毕业设计 081919
  • (附源码)ssm失物招领系统 毕业设计 182317
  • (四)c52学习之旅-流水LED灯
  • (详细文档!)javaswing图书管理系统+mysql数据库
  • (一)插入排序
  • (已解决)vscode如何选择python解释器
  • (转载)hibernate缓存