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);
	}
相关推荐
黄毛火烧雪下7 分钟前
高效的项目构建和优化之前端构建工具
前端
90后的晨仔35 分钟前
在 macOS 上轻松获取 GIF 图片总时长:多种实用方法详解
前端
技术钱35 分钟前
vue3前端解析excel文件
前端·vue.js·excel
mapbar_front1 小时前
顺利通过试用期:避开三大陷阱,掌握三个关键点
前端·面试
韩立学长1 小时前
【开题答辩实录分享】以《智慧校园勤工俭学信息管理系统的设计与实现》为例进行答辩实录分享
vue.js·spring boot·微信小程序
掘金安东尼1 小时前
Transformers.js:让大模型跑进浏览器
开发语言·javascript·ecmascript
why技术1 小时前
1K+Star的开源项目能给一个在校大学生带来什么?
前端·人工智能·后端
@PHARAOH1 小时前
HOW - localstorage 超时管理方案
前端·javascript·vue.js
im_AMBER2 小时前
React 05
开发语言·前端·javascript·笔记·学习·react.js·前端框架
showker2 小时前
ecstore等产品开启缓存-后台及前台不能登录原因-setcookie+session问题
java·linux·前端