我在一个网站上工作,在那里使用Svelte和svelte-routing库。svelte-routing库有一个名为navigate(path)的方法。我只需单击一个按钮就可以使用此函数,它可以完美地工作。但在我的routeHandling.js文件中,它并没有像预期的那样工作。我可以看到它在浏览器中设置了url,但它停留在同一页面上,所以我必须按F5 (重新加载页面)来加载页面。 import {navigate} from "svelte-routing";
import * as axios from "axios";
export function
我正在重构一个React应用程序,它从服务器上的json文件中加载语言标签。使用Ajax调用从服务器中提取数据,Ajax调用更新包含所有语言标签的存储。下面是一些代码,说明了这个问题。
app.js
<script>
import { storeLang, getLangLabels } from './store'
// get labels from server
getLangLabels()
// set language labels in a reactive variable
$: LABELS = $storeLang.labels
</s
我不知道为什么这不更新。我对Svelte比较陌生,但我知道如何使用thing = thing方法强制更新对象数组。
尽管如此,我还是不知道为什么这个不能重新渲染?首先,我把它当作矩阵,我想,也许是有一些嵌套破坏了它,但现在,这实际上只是一个平面阵列。它正在更新矩阵上的点击,但不触发重新渲染。
<script>
import Nested from './Nested.svelte';
let matrix = new Array(9).fill(null)
let turn = 0
let handleChange
我已经创建了一个在获取数据时使用的简单组件,我还想在等待周期运行时禁用该按钮,我可以在模板中使用{disabled = true}和{disabled = false},但这会渲染这些值,有没有其他方法可以做到这一点?
<script>
import Fa from "@node_modules/svelte-fa/src/fa.svelte"
import { faSpinner } from "@fortawesome/free-solid-svg-icons"
export let text = ""
expor
我还没有在svelte 3中找到这个特性。我希望它是这样的..
App.svelte
<Error>
<p>Can't connect to the server!</p>
</Error>`
Error.svelte
<div>{props.children}</div>
我想让App.svelte显示:
<div><p>Can't connect to the server!</p></div>
我只知道如何使用React的props.childre
我想找到一条通往斯维特的路,结合传单。我被困的地方是如何正确地将传单组件分割成文件。为了学习,我尝试用svelte构建正式的。
这就是我的app.svelte的样子:
<script>
import L from 'leaflet';
import { onMount } from "svelte";
import { Circle } from "./components/Circle.svelte";
let map;
onMount(async () => {
map = L.map(
我想使用一些来自的web组件。但我不知道如何在Svelte中使用它们,因为svelte将web组件视为svelte组件。
当我试图用它们作为,
<script lang="ts">
import { Button } from "@vscode/webview-ui-toolkit"
</script>
<main>
<Button appearance="primary">Text</Button>
</main>
我知道这个错误,
Element does not
如何获取当前svelte文件的所有属性?
例如,这个Component1.svelte
<script>
let x = '';
let y = '';
let z = '';
onMount(function(){
console.log( what? );
// need to print x, y, and z which set by other code
// that using/importing this file
// without defining one by
CompOne如何在CompTwo中运行“测试”函数?
CompOne.svelte
<script>
import {test} from './CompTwo.svelte'
</script>
<!-- Some style and HTML tags for this component -->
CompTwo.svelte
<script>
export const test = () => { console.log('testing function') }
</script&
我有一个项目结构: __layout.svelte <- requests header nav links in its load function
articles/
__layout.svelte <- requests list of tags for left sidebar in its load function + provides column layout
index.svelte <- list of all articles
u[id].svelte <- list of articles made by specifi
每当"view.current“更改时,我都想重新复制"Body”(我的svelte组件),以便它呈现相应的.svelte视图/组件:
App.svelte
<script>
import Header from "./components/Header.svelte";
import Footer from "./components/Footer.svelte";
import Body from "./components/Body.svelte";
import Log
我有这个基本的应用程序,有一些组件有一个公共的load方法。对于某些操作,我想在当前的svelte:component上调用该方法,但是我不知道如何获得对组件实例的引用。一个人怎么能这么做?
<script>
import router from 'page'
import Wines from './pages/Wines.svelte'
import Entry from './pages/Entry.svelte'
import TitleBar from
我有一个Error.svelte组件,它有一个包含可写存储的<script context="module">和一个导出的“addError”函数,用于更改存储内容。 Error.svelte <script context="module">
import {get, writable} from "svelte/store";
let errorStore = writable([])
export function addError(error) {
let error
所以我用svelte创建组件,并在其中添加自定义逻辑,
但是编译好了。
然后使用本机javascript使用编译后的版本,而不执行svelte的npm安装。
基本上,我希望我能做这样的事情:
function test(text) {
// for example let's add with native JS this component
document.body.innerHTML += `<MyCard myParameter="${text}">` // when calling myCard it will create also s