Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<script context="module"> 翻译校准 #18

Open
Copyes opened this issue Jun 3, 2019 · 0 comments
Open

<script context="module"> 翻译校准 #18

Copyes opened this issue Jun 3, 2019 · 0 comments

Comments

@Copyes
Copy link
Collaborator

Copyes commented Jun 3, 2019

具有context =“module”属性的<script>的模块在首次解析时运行一次,而不是每个组件实例都运行一次。在此类型的模块中申明的Values可以被普通的<script>标签访问到(包括组件标签)但是相反则无法这么使用。
你可以从此模块中export这些绑定值,并且他们会成为编译过的模块的导出值
你无法export默认值,因为默认导出的是组件本身。

<script context="module">
	let totalComponents = 0;

	// this allows an importer to do e.g.
	// `import Example, { alertTotal } from './Example.svelte'`
	export function alertTotal() {
		alert(totalComponents);
	}
</script>

<script>
	totalComponents += 1;
	console.log(`total number of times this component has been created: ${totalComponents}`);
</script>

@yuwanli @tgxpuisb @dujuncheng @daixinye

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant