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);
	}
相关推荐
清幽竹客31 分钟前
vue-37(模拟依赖项进行隔离测试)
前端·vue.js
vvilkim31 分钟前
Nuxt.js 页面与布局系统深度解析:构建高效 Vue 应用的关键
前端·javascript·vue.js
paopaokaka_luck33 分钟前
基于SpringBoot+Vue的电影售票系统(协同过滤算法)
vue.js·spring boot·后端
滿35 分钟前
Vue3 父子组件表单滚动到校验错误的位置实现方法
前端·javascript·vue.js
专注VB编程开发20年35 分钟前
javascript的类,ES6模块写法在VSCODE中智能提示
开发语言·javascript·vscode
夏梦春蝉2 小时前
ES6从入门到精通:模块化
前端·ecmascript·es6
拓端研究室3 小时前
视频讲解:门槛效应模型Threshold Effect分析数字金融指数与消费结构数据
前端·算法
工一木子4 小时前
URL时间戳参数深度解析:缓存破坏与前端优化的前世今生
前端·缓存
半点寒12W5 小时前
微信小程序实现路由拦截的方法
前端
某公司摸鱼前端6 小时前
uniapp socket 封装 (可拿去直接用)
前端·javascript·websocket·uni-app