事件侦听器

  1. <script>
  2. export default {
  3. mounted() {
  4. this.creatInterval('hello')
  5. this.creatInterval('world')
  6. },
  7. creatInterval(msg) {
  8. let timer = setInterval(() => {
  9. console.log(msg)
  10. }, 1000)
  11. this.$once('hook:beforeDestroy', function() {
  12. clearInterval(timer)
  13. })
  14. }
  15. }
  16. </script>

$attr 透传

手动挂载 vm.$mount

路由参数解耦

props: true

  1. const router = new VueRouter({
  2. routes: [{
  3. path: '/user/:id',
  4. component: User,
  5. props: true
  6. }]
  7. })
  8. // 使用
  9. export default {
  10. props: ['id'],
  11. methods: {
  12. getParamsId() {
  13. return this.id
  14. }
  15. }
  16. }