VUE前端问题

一、图表内容不显示

javascript 复制代码
watch: {
    chartData3: {
      handler() {
        this.init();
      },
    },
    timeData3: {
      handler() {
        this.init();
      },
    },
  },

添加上面代码可以动态监控数据,实现图表的展示。

二、背景图片报错显示不出来

解决方法:

css 复制代码
background: url(~@/assets/login/e.png)

将引入改为 ~@方式引入即可

~@的意思: @是webpack设置的路径名,代表的是src目录,可以在build / webpack.base.conf.js更改设置

三、轨迹不随地图缩放而缩放

javascript 复制代码
init() {
		this.olSource_line = new VectorSource();
        console.log("this.viewZoom1:", this.viewZoom);
		this.olLayer_line = new VectorLayer({
			source: this.olSource_line,
			style: (feature) => {
				console.log("this.viewZoom2:", this.viewZoom);
				let coords = feature.getGeometry().getCoordinates();
				return [
					new Style({
						stroke: new Stroke({
							color: this.style.line_stroke,
							width: this.viewZoom + 2,
						}),
					}),
					...this.getPointsStyle(coords)
				]
			},
		});
		this.olMap.addLayer(this.olLayer_line);
}

地图缩放时this.viewZoom1在改变,但是this.viewZoom2不变。

解决方法:

添加监听函数监听数据变化

javascript 复制代码
init() {
		this.olSource_line = new VectorSource();
		this.olLayer_line = new VectorLayer({
			source: this.olSource_line,
			style: (feature) => {
				console.log("this.viewZoom:", this.viewZoom);
				let coords = feature.getGeometry().getCoordinates();
				return [
					new Style({
						stroke: new Stroke({
							color: this.style.line_stroke,
							width: this.viewZoom + 2,
						}),
					}),
					...this.getPointsStyle(coords)
				]
			},
		});
		this.olMap.addLayer(this.olLayer_line);

		// 添加地图缩放事件监听器
		this.olMap.on('moveend', () => {
			this.viewZoom = this.olMap.getView().getZoom();
			this.updateLineStyle(); // 更新轨迹线样式
		});
	}
	updateLineStyle() {
		// 在这里更新轨迹线的样式,可以根据新的 this.viewZoom 值进行相应的样式调整
		let styleFunction = (feature) => {
			let coords = feature.getGeometry().getCoordinates();
			console.log("this.viewZoom:", this.viewZoom);
			return [
				new Style({
					stroke: new Stroke({
						color: this.style.line_stroke,
						width: this.viewZoom + 2,
					}),
				}),
				...this.getPointsStyle(coords)
			];
		};

		this.olLayer_line.setStyle(styleFunction);
	}
相关推荐
2501_943782351 小时前
【共创季稿事节】猜数字游戏:二分法思维与交互式反馈
前端·游戏·microsoft·harmonyos·鸿蒙·鸿蒙系统
GV191rLvq1 小时前
基于Socket实现的最简单的Web服务器【ASP.NET原理分析】
服务器·前端·asp.net
吠品2 小时前
LangChain 里 tool_call_id 为空?一次 MCP 工具集成的排查记录
前端
柒和远方2 小时前
Phase 7.4 学习博客:为什么多 API 项目需要 Swagger / OpenAPI
前端·后端·架构
张龙6872 小时前
拼多多开放平台对接踩坑实录:从 CLIENT_ID 配置到 MD5 签名算法的完整填坑指南
前端
GuWenyue2 小时前
提示词彻底过时?一套上下文工程方案,3步让LLM落地生产,代码直接复用
前端·javascript·人工智能
柒和远方2 小时前
Phase 7.3 复盘:后台任务不只是“扔进队列”,还要能被看见
前端·后端·架构
2501_943782352 小时前
【共创季稿事节】 倒计时器:时分秒选择器与定时器的协同工作
前端·华为·harmonyos·鸿蒙·鸿蒙系统
奶油mm2 小时前
公司技术债堆积如山,我一人之力用 Vue3 偷换了整个前端架构
前端·vue.js
用户938515635072 小时前
深入理解 JavaScript 中的 this 与数据存储的奥秘
前端·javascript