Vux: 关于this.$vux的使用

Created on 24 May 2017  ·  7Comments  ·  Source: airyland/vux

我在官网demo上看到了toast可以这样使用
this.$vux.toast.show({
text: 'Hello World',
onShow () {
console.log('Plugin: I\'m showing')
},
onHide () {
console.log('Plugin: I\'m hiding')
_this.show9 = false
}
})
可是我这么复制 $vux.toast会报错 有时候$vux也会报错 我想知道$vux.xxx是不是需要什么引用 因为在文档里翻了翻没有找到这方面的说明 所以来问一下

componentoast

Most helpful comment

@DaoqiuDong @dengxiaozhen
$vux是挂载在vue上的,所以只有在组件内可以通过this访问,或者直接引用并通过Vue来访问

import Vue from 'vue'
Vue.$vux.toast.text("text", "middle");

还有一种思路是在根组件app下写一个toast,他的显示状态依赖于vuex中设定的状态,在需要toast的地方处理好状态就行了

<toast v-model="$store.state.isToastShow" type="text" :time="800" is-show-mask text="Hello World" :position="$store.state.toastPosition"></toast>

All 7 comments

在 main.js 引入插件,在组件里就可以调用。

https://vux.li/#/zh-CN/components_dialog?id=toast

谢谢作者 我一直都很纳闷这种东西怎么用

利用Plugin的方式,可以配置同意的on-show回调吗?

想在自己封装的axios全局拦截器加一个全局的错误打印,无法调用额

@DaoqiuDong 大佬解决了吗?我也碰到这个问题了。在main.js 这么写的

import { ToastPlugin } from 'vux'
Vue.use(ToastPlugin)

然后自己封装了 axios 的 js,在里面调用就报错

this.$vux.toast.show({
  text: 'Loading'
})

报错信息:
TypeError: Cannot read property 'toast' of undefined

@DaoqiuDong @dengxiaozhen
$vux是挂载在vue上的,所以只有在组件内可以通过this访问,或者直接引用并通过Vue来访问

import Vue from 'vue'
Vue.$vux.toast.text("text", "middle");

还有一种思路是在根组件app下写一个toast,他的显示状态依赖于vuex中设定的状态,在需要toast的地方处理好状态就行了

<toast v-model="$store.state.isToastShow" type="text" :time="800" is-show-mask text="Hello World" :position="$store.state.toastPosition"></toast>

@DaoqiuDong 大佬解决了吗?我也碰到这个问题了。在main.js 这么写的

import { ToastPlugin } from 'vux'
Vue.use(ToastPlugin)

然后自己封装了 axios 的 js,在里面调用就报错

this.$vux.toast.show({
  text: 'Loading'
})

报错信息:
TypeError: Cannot read property 'toast' of undefined
你裏面的this.$vux中的this有問題,要是頁面的上下文this才行

Was this page helpful?
0 / 5 - 0 ratings

Related issues

525729985 picture 525729985  ·  4Comments

iqiuye picture iqiuye  ·  4Comments

lkangd picture lkangd  ·  5Comments

varHarrie picture varHarrie  ·  4Comments

wonghoman picture wonghoman  ·  4Comments