Difference between revisions of "Components"
Jump to navigation
Jump to search
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
--app.vue | |||
<pre> | |||
<template> | |||
<div class="container"> | |||
<div class="row"> | |||
<div class="col-xs-12"> | |||
<app-user></app-user> | |||
</div> | |||
</div> | |||
</div> | |||
</template> | |||
<script> | |||
import User from "./User.vue"; | |||
export default { | |||
components: { | |||
appUser: User | |||
} | |||
}; | |||
</pre> | |||
--user.vue | --user.vue | ||
<pre> | <pre> | ||
Line 40: | Line 60: | ||
}; | }; | ||
</script> | </script> | ||
</pre> | |||
-- UserDetail.vue | |||
<pre> | |||
<template> | |||
<div class="component"> | |||
<h3>You may view the User Details here</h3> | |||
<p>Many Details</p> | |||
<p>User Name: {{name}}</p> | |||
</div> | |||
</template> | |||
<script> | |||
export default { | |||
props: ["name"] | |||
}; | |||
</script> | |||
<style scoped> | |||
div { | |||
background-color: lightcoral; | |||
} | |||
</style> | |||
</pre> | </pre> | ||
==[[#top|Back To Top]]-[[Main_Page| Home]] - [[VueJs|Category]]== | ==[[#top|Back To Top]]-[[Main_Page| Home]] - [[VueJs|Category]]== |
Latest revision as of 23:41, 11 June 2018
--app.vue
<template> <div class="container"> <div class="row"> <div class="col-xs-12"> <app-user></app-user> </div> </div> </div> </template> <script> import User from "./User.vue"; export default { components: { appUser: User } };
--user.vue
<template> <div class="component"> <h1>The User Component</h1> <p>I'm an awesome User!</p> <button @click="changeName">Change my name</button> <hr> <div class="row"> <div class="col-xs-12 col-sm-6"> <app-user-detail :name="name"></app-user-detail> </div> <div class="col-xs-12 col-sm-6"> <app-user-edit></app-user-edit> </div> </div> </div> </template> <script> import UserDetail from "./UserDetail.vue"; import UserEdit from "./UserEdit.vue"; export default { data: function() { return { name: "Robert" }; }, methods: { changeName() { this.name = "Anna"; } }, components: { appUserDetail: UserDetail, appUserEdit: UserEdit } }; </script>
-- UserDetail.vue
<template> <div class="component"> <h3>You may view the User Details here</h3> <p>Many Details</p> <p>User Name: {{name}}</p> </div> </template> <script> export default { props: ["name"] }; </script> <style scoped> div { background-color: lightcoral; } </style>