我想导入使用“window”属性的 apexChart 库,但在控制台中出现错误。
[vite] Error when evaluating SSR module /src/routes/prehled.svelte:
ReferenceError: window is not defined
Run Code Online (Sandbox Code Playgroud)
我尝试在安装后使用 apexCharts,但错误并没有消失。
[vite] Error when evaluating SSR module /src/routes/prehled.svelte:
ReferenceError: window is not defined
Run Code Online (Sandbox Code Playgroud)
当我确定浏览器存在时,我尝试导入 apexCharts。
<script>
import ApexCharts from 'apexcharts'
import { onMount } from 'svelte'
const myOptions = {...myOptions}
onMount(() => {
const chart = new ApexCharts(document.querySelector('[data-chart="profit"]'), myOptions)
chart.render()
})
</script>
Run Code Online (Sandbox Code Playgroud)
但我收到错误“‘导入’和‘导出’可能只出现在顶层”
我尝试在 svelte.config.js 中禁用 ssr
import { browser } from '$app/env'
if (browser) {
import ApexCharts from 'apexcharts'
}
Run Code Online (Sandbox Code Playgroud)
我尝试创建一个导入 apexChart 库的组件,并创建了一个条件,仅当浏览器存在时才使用该组件 …
如何删除 VS Code 未使用的 CSS 选择器警告?此警告存在于我使用的所有文件中<style lang="scss">。我知道我不在.btn某些组件中使用类,但我希望这个类作为全局 css。
我的svelte.config.js:
const config = {
onwarn: (warning, handler) => {
const { code, frame } = warning;
if (code === "css-unused-selector")
return;
handler(warning);
},
preprocess: [
preprocess({
defaults: {
style: 'scss'
},
postcss: true,
scss: {
prependData: `@import 'src/scss/global.scss';`
}
})
],
};
Run Code Online (Sandbox Code Playgroud)
请问有人可以帮助我吗?
我有默认的 jest.config.js 但当我想运行单元测试时,我收到一条错误消息:
验证错误:找不到预设@vue/cli-plugin-unit-jest/presets/typescript-and-babel。
我正在使用 vue 2 与合成 api 插件和打字稿。
笑话.config.js:
module.exports = {
preset: '@vue/cli-plugin-unit-jest/presets/typescript-and-babel'
}
Run Code Online (Sandbox Code Playgroud)
示例.spec.ts:
import { shallowMount } from '@vue/test-utils'
import HelloWorld from '@/components/HelloWorld.vue'
describe('HelloWorld.vue', () => {
it('renders props.msg when passed', () => {
const msg = 'new message'
const wrapper = shallowMount(HelloWorld, {
props: { msg }
})
expect(wrapper.text()).toMatch(msg)
})
})
Run Code Online (Sandbox Code Playgroud) svelte ×2
sveltekit ×2
apexcharts ×1
console ×1
css ×1
import ×1
jestjs ×1
sass ×1
typescript ×1
vue.js ×1