nuxt.js引入echarts旋转地球
时间: 2023-10-27 13:46:29 浏览: 204
Nuxt.js之自动路由原理的实现方法
首先,在 Nuxt.js 项目中引入 echarts:
1. 安装 echarts: `npm install echarts --save`
2. 在 nuxt.config.js 中配置 echarts:
```js
module.exports = {
head: {
script: [
{
src: 'https://cdn.jsdelivr.net/npm/echarts@4.9.0/dist/echarts.min.js',
type: 'text/javascript'
}
]
}
}
```
然后,在页面中创建一个容器用于显示 echarts:
```html
<template>
<div id="chart" style="width: 100%; height: 500px;"></div>
</template>
```
在页面的 mounted 钩子中初始化 echarts:
```js
<script>
export default {
mounted() {
const chart = echarts.init(document.getElementById('chart'))
chart.setOption({
globe: {
baseTexture: 'https://cdn.jsdelivr.net/npm/echarts-gl@1.1.1/dist/map/world.jpg',
heightTexture: 'https://cdn.jsdelivr.net/npm/echarts-gl@1.1.1/dist/map/world.topo.bathy.200401.jpg',
displacementScale: 0.1,
shading: 'realistic',
realisticMaterial: {
roughness: 0.2
},
postEffect: {
enable: true,
bloom: {
enable: false
},
SSAO: {
enable: true,
intensity: 1.2
},
depthOfField: {
enable: false,
focalDistance: 150
}
},
light: {
main: {
intensity: 5,
shadow: true,
shadowQuality: 'high'
},
ambient: {
intensity: 0
},
ambientCubemap: {
texture: 'https://cdn.jsdelivr.net/npm/echarts-gl@1.1.1/dist/data-gl/asset/canyon.hdr',
exposure: 1,
diffuseIntensity: 0.5,
specularIntensity: 2
}
},
viewControl: {
autoRotate: true,
autoRotateAfterStill: 10,
distance: 200,
minDistance: 50,
maxDistance: 500,
alpha: 20,
beta: 10,
minBeta: -90,
maxBeta: 90,
target: [0, 0, 0]
},
layers: [
{
type: 'blend',
blendTo: 'emission',
texture: 'https://cdn.jsdelivr.net/npm/echarts-gl@1.1.1/dist/data-gl/asset/glow.png'
},
{
type: 'overlay',
texture: 'https://cdn.jsdelivr.net/npm/echarts-gl@1.1.1/dist/data-gl/asset/starfield.jpg',
shading: 'color',
distance: 50
}
]
}
})
}
}
</script>
```
这样就可以在页面中显示一个旋转的地球了。可以修改 `viewControl` 中的参数来控制视角和旋转速度等,具体参数详见 echarts 文档。
阅读全文