小编owf*_*owf的帖子

在VUE 3中的Async方法中调用SweetAlert2

如果无法从服务器检索数据,我尝试弹出 sweetalert

我在 main.js 中导入了 Sweet Alert :

import VueSweetalert2 from 'vue-sweetalert2'
import 'sweetalert2/dist/sweetalert2.min.css'

const app = createApp(App)
app.use(VueSweetalert2)
app.mount('#app')
Run Code Online (Sandbox Code Playgroud)

在 Table.vue 组件内,我尝试调用 swal 但收到错误消息 (undefined $this.swal) :

<script>
import axios from 'axios'
import { onMounted, ref } from 'vue'

export default {
    setup() {
        let transactions = ref([])

        onMounted(() => {
            getTransactions()
        })

        async function getTransactions() {
            try {
                let { data } = await axios.get('http://127.0.0.1:8000/api/transactions')
                transactions.value = data.data
            } catch(e) {
                this.$swal('Something went wrong.')
            }
        }

        return { …
Run Code Online (Sandbox Code Playgroud)

vue.js sweetalert2 vuejs3

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

sweetalert2 ×1

vue.js ×1

vuejs3 ×1