Created
June 19, 2020 07:16
-
-
Save shershen08/7b9661ef1a4bb7c1d90cbf4181add23c to your computer and use it in GitHub Desktop.
VueJS v3 some features demo
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width,initial-scale=1.0"> | |
</head> | |
<body> | |
<!-- vue --> | |
<div id="app"></div> | |
<!-- portals --> | |
<div id="wrapper"></div> | |
<script src="http://unpkg.com/vue@next"></script> | |
<script> | |
// 1 createApp syntax | |
const { createApp, ref } = Vue; | |
const App = { | |
// 2 data is a function | |
data: () => ({ | |
someValue: false | |
}), | |
setup(props, ctx) { | |
const name = ref("Code"); | |
setTimeout(() => { | |
name.value = 'chrysalis' | |
}, 1000) | |
return { name }; | |
}, | |
// 3 - multy-root | |
template: ` | |
<div></div> | |
<h1> | |
Hello {{ name }} ! | |
-- | |
someValue: {{someValue}} | |
<teleport to="#wrapper"> | |
<p v-if="true">i am in #wrapper</p> | |
</teleport> | |
</h1>`, | |
// 4 - explicit emit | |
emits: [ 'NAME_EVENT', 'remove' ] | |
// P ------> C | |
// props: { | |
// foo: { | |
// default: 'bar', | |
// type: String | |
// } | |
// } | |
// this.$emit(NAME_EVENT, { | |
// }) | |
// P <------ C | |
}; | |
// | |
createApp(App).mount("#app"); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment