ASCII码 ASCII码

绑定事件练习、组件练习、路由练习

发布于:2022-06-07 11:15:24  栏目:技术文档

app.vue

  1. <template>
  2. <div>
  3. <router-link to="/">Home</router-link> |
  4. <router-link to="/about">about</router-link>
  5. <br>
  6. <input type="text" v-model="password">
  7. <div v-once>{{password}}</div>
  8. <div>{{password}}</div>
  9. <div v-text="password"></div>
  10. <div v-html="htmlcode"></div>
  11. <div v-pre>{{htmlcode}}</div>
  12. <div :title="btn">按钮</div>
  13. <OneCom></OneCom>
  14. <OneCom><div>Hello wolrd!</div></OneCom>
  15. <OneCom :msg="msg"></OneCom>
  16. <router-view />
  17. </div>
  18. </template>
  19. <style>
  20. </style>
  21. <script>
  22. import OneCom from './components/OneCom.vue';
  23. export default{
  24. data(){
  25. return{
  26. password: "默认密码:123",
  27. htmlcode: "<i>Hi, Dave</i>",
  28. msg:'www.php.cn',
  29. btn: "button"
  30. };
  31. },
  32. methods: {
  33. clicked(){
  34. console.log("hi dave");
  35. },
  36. sayhi(){
  37. console.log("Hahaha");
  38. }
  39. },
  40. components:{
  41. OneCom,
  42. }
  43. }
  44. </script>

OneCom.vue

  1. <template>
  2. <div>
  3. this is one com.
  4. </div>
  5. <div>{{msg}}</div>
  6. <div>{{getmsg()}}</div>
  7. <slot></slot>
  8. </template>
  9. <script>
  10. export default{
  11. props:['msg'],
  12. methods:{
  13. getmsg(){
  14. this.$parent.sayhi();
  15. }
  16. }
  17. }
  18. </script>
  19. <style>
  20. </style>
相关推荐
阅读 +