博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何在脚本模块外部的Sapper中访问URL参数
阅读量:2507 次
发布时间:2019-05-11

本文共 770 字,大约阅读时间需要 2 分钟。

Suppose you’re building a Svelte application using Sapper, and you have a dynamic page route, for example /routes/[id].svelte.

假设您正在使用Sapper构建Svelte应用程序,并且具有动态页面路由,例如/routes/[id].svelte

You want to get the dynamic part of the URL (the id in this case), and you know you can get it in the preload() function in the <script context="module"> part of the component:

您想要获取URL的动态部分(在这种情况下为id ),并且知道可以在组件的<script context="module">部分的preload()函数中获取它:

But the problem is that you need to use it outside of preload(), to perform something else.

但是问题是您需要在preload()之外使用它来执行其他操作。

The way to do so is to return it from preload, and define it as a prop of the component, using the usual export * syntax.

这样做的方法是从preload返回它,并使用通常的export *语法将其定义为组件的支持。

Here’s an example:

这是一个例子:

翻译自:

转载地址:http://dhmgb.baihongyu.com/

你可能感兴趣的文章
二值图像连通区域标记
查看>>
MVC in Javascript
查看>>
eclipse 创建的Android工程的结构
查看>>
第8章 Android异常与性能优化相关面试问题
查看>>
linux 定时备份文件夹
查看>>
有道单词导入 大量有道单词 生词本 批量导入 添加 有道单词XML 背单词
查看>>
jQuery Easing动画效果扩展插件
查看>>
bzoj 1002 [FJOI2007]轮状病毒 Matrix-Tree定理+递推
查看>>
Selenium WebDriver- 操作JavaScript的Alert弹窗
查看>>
娘的,自己的求逆序对模板又不好使了。。。。。。。。
查看>>
C#面向对象模式设计第十四讲:Template Method 模板模式(行为型模式)
查看>>
linux后台运行命令:&和nohup
查看>>
springboot + shiro学习(配置SecurityManager,Realm)
查看>>
http://desk.zol.com.cn/1600x900/
查看>>
Linux基础之命令练习Day3-文件管理:cat,tar,gzip,vim,ln
查看>>
iOS中使用nil NULL NSNULL的区别
查看>>
Hdu1754-线段树-单点更新
查看>>
在python中使用正则表达式(一)
查看>>
asp.net mvc 4.0的部署
查看>>
WordPress资源站点推荐
查看>>