-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add watchEffect and script setup example
- Loading branch information
1 parent
cd223f9
commit 8d2f87a
Showing
3 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<template> | ||
<div v-if="hasContent"> | ||
<div id="contentInfo" /> | ||
</div> | ||
|
||
<div v-else> | ||
<div id="noContent" /> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { ref, watchEffect, inject } from 'vue' | ||
const type = inject('someType') | ||
const hasContent = ref(false) | ||
watchEffect(() => { | ||
if (type === 'content') { | ||
hasContent.value = true | ||
} | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { mount } from '../../src' | ||
import ScriptSetup_WatchEffect from '../components/ScriptSetup_WatchEffect.vue' | ||
|
||
it('watchEffect works with script setup', () => { | ||
const wrapper = mount(ScriptSetup_WatchEffect, { | ||
global: { | ||
provide: { someType: 'content' } | ||
} | ||
}) | ||
|
||
expect(wrapper.find('#contentInfo').exists()).toBe(true) | ||
}) |