html通过CDN引入Vue使用Vuex以及Computed、Watch监听

html通过CDN引入Vue使用Vuex以及Computed、Watch监听

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

功能说明:需要开发一个dashboard,也就是大屏可视化,多个模块,然后由图表作为主要内容。那么就意味着需要全局监听,如果筛选条件改变,那么所有的组件都需要监听到这个改变,做出相应的反应。

效果图

在这里插入图片描述

代码实现

store.js

const store = new Vuex.Store({state: {msg: 'Hello World',count: 5},mutations: {increment(state, payload) {console.log('的话',state,payload)state.count ++}},actions: {increment(context, payload) {setTimeout(() => {context.commit('increment', payload);}, 2000);}},getters: {msg(state) {return state.msg.toUpperCase();},count(state) {return state.count;}},
});

然后将store挂载到Vue上
主页面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"><!-- <grid-layout :layout="layout" :col-num="12" :row-height="30" :is-draggable="true" :is-resizable="true"><grid-item v-for="item in layout" :key="item.i" :x="item.x" :y="item.y" :w="item.w" :h="item.h" class="grid-item">{{ item.i }}</grid-item></grid-layout> --><el-button @click="cliackDialog" type="success">Button</el-button><el-button @click="increment" type="success">{{count}}</el-button><el-dialog :visible.sync="visible" title="Hello world"><p>Try Element</p></el-dialog><my-component title="标题" content="This is the first component"></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,},computed: {count() {return this.$store.state.count;}},watch:{'$store.state.count':{handler(newVal,oldVal){console.log('主界面监听Vuex',newVal,oldVal)}}},mounted(){this.initEchart()},methods: {increment() {this.$store.commit('increment');},cliackDialog(){this.visible = !this.visible},}   });</script>
</body>
</html>

子组件js

{/* <script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.4.3/echarts.min.js"></script> */}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>
`
// 导入 mapState 辅助函数  这样监听和通过$store监听都可以
// const { mapState } = Vuex;// my-component.js
Vue.component('my-component', {props: ['title', 'content'],template: htmlstr,data(){return{str:1}},// computed: {//   ...mapState(['count'])// },watch: {// count:{//   handler(v){//     // 在 count 发生变化时执行的操作//     console.log('子组件监听Vuex', v);//   }// },'$store.state.count':{handler(newVal,oldVal){console.log('子组件监听Vuex',newVal,oldVal)}}},mounted(){// setTimeout(()=>{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);})}}
});

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/213044.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

K8S学习指南-minikube的安装

简介 Minikube 是一个用于在本地开发环境中运行 Kubernetes 集群的工具。它允许开发人员在单个节点上体验 Kubernetes&#xff0c;无需配置复杂的生产环境。本指南将详细介绍在 Windows、CentOS 和 Ubuntu 系统上安装 Minikube 的步骤。 1. Windows 系统安装 1.1 &#xff1…

期末速成数据库极简版【查询】(3)

目录 多表查询 【8】多表连接——内连接 &#x1f642;等值连接 &#x1f642;自然连接 &#x1f642;非等值连接 【9】多表连接——外连接 【10】交叉连接不考 【11】联合查询 【12】扩展多表连接 【13】嵌套查询 &#x1f642; 多表查询 【8】多表连接——内连…

HIVE学习(hive基础)

HIVE基础介绍 一、HIVE简介二、hive的数据类型1、基本数据类型2、复合数据类型 三、HIVE的DDL操作四、创建一个表1. 建表语句 五、修改表结构1.修改表名2. 列修改或增加3. 修改分区 五、常见函数六、一对一关联left join左关联right join 右关联内连接全连接查询只有A表的数据 …

计算机视觉-机器学习-人工智能顶会 会议地址

计算机视觉-机器学习-人工智能顶会 会议地址 最近应该要整理中文资料的参考文献&#xff0c;很多会议文献都需要补全会议地点&#xff08;新国标要求&#xff09;。四处百度感觉也挺麻烦的&#xff0c;而且没有比较齐全的网站可以搜索。因此自己整理了一下计算机视觉-机器学习…

OSPF路由协议

随着Internet技术在全球范围的飞速发展&#xff0c;OSPF已成为目前应用最广泛的路由协议之一。OSPF&#xff08;Open Shortest Path First&#xff09;路由协议是由IETF&#xff08;Internet Engineering Task Force&#xff09;IGP工作组提出的&#xff0c;是一种基于SPF算法的…

JS 云服务 Deno Depoly 宣布,推出定时运行功能 Deno Cron

如果需要定时执行 JS 脚本&#xff0c;以后多一个选项。 Web 构建日益复杂。编写现代软件包括利用云基础设施、剖析模板代码和管理复杂的配置&#xff0c;而开发人员只想专注于编写业务逻辑。 Deno 旨在通过删除配置和不必要的模板&#xff0c;从根本上简化 Web 开发。我们将无…

网络攻击(三)--攻击阶段

5. 威胁建模阶段 目标 了解威胁建模阶段的工作内容 工作内容 威胁建模主要使用在情报搜集阶段所获取到的信息&#xff0c;来标识出目标系统上可能存在的安全漏洞与弱点。 在进行威胁建模时&#xff0c;确定最为高效的攻击方法、所需要进一步获取到的信息&#xff0c;以及从…

【前端】CSS浮动(学习笔记)

一、浮动 1、传统网页布局 网页布局的本质&#xff1a;用 CSS 来摆放盒子&#xff0c;把盒子摆放到相应位置。 CSS 提供了三种传统布局方式&#xff08;盒子如何进行排列顺序&#xff09; 普通流&#xff08;标准流&#xff09;浮动定位 实际开发中&#xff0c;一个页面基…

Go 反射技术判断结构体字段数据为空

Api介绍 在Go语言中&#xff0c;反射API用于在运行时检查类型信息、获取和修改变量的值以及调用对象的方法。反射API包含了一组函数和类型&#xff0c;可以在程序运行时动态地操作对象。 以下是一些常用的反射API&#xff1a; reflect.TypeOf&#xff1a;返回一个值的类型信息。…

并查集基础模板

题目我上面有人儿 代码 #include <bits/stdtr1c.h> using namespace std; const int N 1005; int f[N]; int n; int siz[N]; // 初始化并查集 // void init() // { // for (int i 1; i < n; i) // { // f[i] i; // 初始化所有的节点都是自己的父节点 //…

Tomcat头上有个叉叉

问题原因&#xff1a; 这是因为它就是个空的tomcat,并没有导入项目运行 解决方案&#xff1a; war模式&#xff1a;发布模式&#xff0c;正式发布时用&#xff0c;将WEB工程以war包的形式上传到服务器 war exploded模式&#xff1a;开发时用&#xff0c;将WEB工程的文件夹直接…

【网络协议】LACP(Link Aggregation Control Protocol,链路聚合控制协议)

文章目录 LACP名词解释LACP工作原理互发LACPDU报文确定主动端确定活动链路链路切换 LACP和PAgP有什么区别&#xff1f;LACP与LAG的关系LACP模式更优于手动模式LACP模式对数据传输更加稳定和可靠LACP模式对聚合链路组的故障检测更加准确和有效 推荐阅读 LACP名词解释 LACP&…

day11 前k个高频元素

// 小顶堆 class mycomparison { public: bool operator()(const pair<int, int>& lhs, const pair<int, int>& rhs) { return lhs.second > rhs.second; } }; vector<int> topKFrequent(vector<int>& nums, int k) { // 要统计元素出现…

智能外呼有什么好处?

智能外呼是一种自动化的电话营销方式&#xff0c;利用AI智能外呼技术和大量数据分析&#xff0c;帮助企业实现与客户之间的高效、精准、个性化的客户沟通&#xff0c;还可以在客户服务、市场营销和销售等方面带来助力。那么&#xff0c;智能外呼有什么好处呢&#xff1f; 1. 提…

spring IOC bean为什么默认是单例的

首先解释一下什么是单例 bean&#xff1f; 单例的意思就是说在 Spring IoC 容器中只会存在一个 bean 的实例&#xff0c;无论一次调用还是多次调用&#xff0c;始终指向的都是同一个 bean 对象 用代码来解释单例 bean public class UserService {public void sayHello() {Syst…

交叉编译工具链makefile

linux系统默认搜索头文件地址&#xff1a;/usr/include/文件夹&#xff1b; Windows系统默认搜索头文件地址&#xff1a;不同软件好像可以设置不同的地址&#xff1b;例如visual studio好像可以设置附加包含目录&#xff0c;包含目录等 Linux系统库文件路径&#xff1a;/lib文…

通过生成模拟释放无限数据以实现机器人自动化学习

该工作推出RoboGen&#xff0c;这是一种生成机器人代理&#xff0c;可以通过生成模拟自动大规模学习各种机器人技能。 RoboGen 利用基础模型和生成模型的最新进展。该工作不直接使用或调整这些模型来产生策略或低级动作&#xff0c;而是提倡一种生成方案&#xff0c;该方案使用…

命运天注定?

罗翔老师经常说&#xff1a;人这一生&#xff0c;能自己决定的也许只有5&#xff05;&#xff0c;有95%是你决定不了的。 不是说事在人为&#xff0c;人定胜天吗&#xff1f; 哪吒也在电影的高潮喊出了&#xff1a;我命由我不由天。 听上去很热血&#xff0c;但实际咱们每个…

Java泛型:详解使用技巧及举例说明

Java泛型&#xff1a;详解使用技巧及举例说明 1. 引言 Java泛型是一项强大的编程概念&#xff0c;它允许我们编写通用的代码&#xff0c;在编写代码时不需要预先指定具体的数据类型。泛型的引入解决了在传统的编程中需要频繁进行类型转换的问题&#xff0c;提高了代码的安全性…

simulink MATLABFunction模块中实时函数调用函数的使用

样例 function Predyy matlabceshi(input, Time_s) input1 input; Time_s1 Time_s; Predyy ee(input1) mm(Time_s1); end 上面是主要部分&#xff0c;下面是被调用部分 function A ee(input1) A input1 * 100; end function B mm(Time_s1) B Time_s1 * 100; end 模型…