Vue composition API 中 this.$message 的写法

vue2.x 通用写法:

...
this.$message({
  type: 'success',
  message: '删除成功'
})
...

vue composition API 写法:

...
setup(props, ctx) {
  ...
  const { $message } = ctx.root
    $message({
      type: 'success',
      message: '删除成功'
  })
  ...
}
...

$store 等也可以用类似的方法

const { $store, $message, $router, $route } = ctx.root
posted @ 2020-10-25 21:10  Leophen  阅读(1025)  评论(2编辑  收藏  举报