Importing ol/style into component
See original GitHub issueHello!
In a Nuxt project, I’m using vl-layer-vector
, and I need to style the features in the component based on some other data that I import from Wikidata.
This example by @ghettovoice shows clearly how to do it, however, because OpenLayers is included from CDN, you can call ol.style.Style()
.
But if I want to import Style
, Fill
, or Stroke
into my component’s <script>
section usingimport Style from 'ol/style/Style'
, I get Cannot use import statement outside a module
.
This has been brought up in https://github.com/ghettovoice/vuelayers/issues/382 and https://github.com/ghettovoice/vuelayers/issues/281, but there was no clear solution suggested.
I’m happy to contribute the solution to the docs once it’s clarified.
Thanks for the great work 😃
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
How to import a CSS file in a React Component - Stack Overflow
C:\Users\User\Documents\pizza-app\client\public\styles\disabledLink.css is the location of the CSS file I'm trying to load. To me it seems like ...
Read more >4 Ways to add Styles to React Component | by Mayank Gupta
4 Ways to add Styles to React Component · 1. Adding Global Style to “index.html” · 2. Inline Style in React Component ·...
Read more >Adding a Stylesheet | Create React App
React, { Component } from 'react'; · import './Button.css'; // Tell webpack that Button.js uses these styles · class Button extends Component {...
Read more >How To Use Styled-Components In React - Smashing Magazine
We do not have to create two styled components for them; we can adapt their styling based on their props. import styled from...
Read more >Different Ways to Write CSS in React
Create a new CSS file in your project directory. Write CSS. Import it into the React file. Like this: import "./style.css" ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I don’t actually understand what a reason of this error. I have made a short investigation of it and found this issue https://github.com/zloirock/core-js/issues/743. And I found that switching of useBuiltIns : “usage” to “entry” is really helps.
Here is my test app https://github.com/ghettovoice/vl-ol-nuxt-test-app. I have setup it with create-nuxt-app package. Then:
plugins
,modules
andbuild
keys https://github.com/ghettovoice/vl-ol-nuxt-test-app/blob/main/nuxt.config.jsAnd it seems working without errors.
Hello @majdal , did you tried setup vuelayers and openlayers inside nuxt as plugin? https://vuelayers.github.io/#/docs/quickstart?id=nuxtjs
UPD also take a note that
ol
package exports ES6 modules, so probably you also need to try this https://nuxtjs.org/docs/2.x/directory-structure/plugins#es6-plugins