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);
	}
相关推荐
Angel_girl31912 分钟前
vue项目使用svg图标
前端·vue.js
難釋懷16 分钟前
vue 项目中常用的 2 个 Ajax 库
前端·vue.js·ajax
Qian Xiaoo18 分钟前
Ajax入门
前端·ajax·okhttp
爱生活的苏苏41 分钟前
vue生成二维码图片+文字说明
前端·vue.js
拉不动的猪43 分钟前
安卓和ios小程序开发中的兼容性问题举例
前端·javascript·面试
炫彩@之星1 小时前
Chrome书签的导出与导入:步骤图
前端·chrome
贩卖纯净水.1 小时前
浏览器兼容-polyfill-本地服务-优化
开发语言·前端·javascript
前端百草阁1 小时前
从npm库 Vue 组件到独立SDK:打包与 CDN 引入的最佳实践
前端·vue.js·npm
夏日米米茶1 小时前
Windows系统下npm报错node-gyp configure got “gyp ERR“解决方法
前端·windows·npm
且白2 小时前
vsCode使用本地低版本node启动配置文件
前端·vue.js·vscode·编辑器