sourcecode

ReferenceError:"Swal 정의되지 않".

copyscript 2022. 7. 31. 22:21
반응형

ReferenceError:"Swal 정의되지 않".

나는 작은 프로젝트 codeigniter과 VueJs과 달콤한 경고javascript 라이브러리를 사용하여 봤는어요, 하지만 나는 내 콘솔에 오류 작업을 하고 있습니다.ReferenceError: "Swal is not defined"한번 나는라고 부른다swall.fire({})내 VueJs 메서드 안에 있습니다.제 코드는 다음과 같습니다.

deleteCustomers(customer_id){
        Swal.fire({
           title: 'Are you sure?',
           text: "You won't be able to revert this!",
           icon: 'warning',
           showCancelButton: true,
           confirmButtonColor: '#3085d6',
           cancelButtonColor: '#d33',
           confirmButtonText: 'Yes, delete it!'
           }).then((result) => {
              axios.post('/Thirdparty/deleteCustomers', {id : customer_id}).then(function(response){
                 console.log(response.data);
                 //alert(response.data.error);
                 Swal.fire(
                 'Deleted!',
                 'Your file has been deleted.',
                 'success'
                 );
              });
           });
     }

그리고 물론 나는 이미를 사용하는 swall 수입해 왔습니다.import Swal from 'sweetalert2';

주의:swall.불만 Vuejs 방법 안에서 일하지 않는다.

여기에 빠른 길 스위트 경고vue js에 구현되는 것이다.

npm install sweetalert2

당신의app.js 레지스터 달콤하경보 사용 가능하게 당신의 모든 구성 요소를 만드는 단계이다.

import swal from 'sweetalert2';
window.Swal = swal;

그리고 어떤 예제(Example.vue)의 구성 요소들에는.

<template>
  ...
</template>
<script>
   export default{
     methods:{
       test(){
         Swal.fire('Test!', 'Hello test message','success');
      } 
    }
   }

More스위트 경보 방법 이곳에서 발견될 수 있다.

당신의main.js 레지스터 달콤하경보 사용 가능하게 당신의 모든 구성 요소를 만드는 단계이다.

import swal from 'sweetalert2';
window.Swal = Swal;

Swal(로 캐피탈 S)과Swal.fire()sweetalert2 버전에 소개됩니다.> 7.20.0.

이전 버전(에서< 7.20.0)를 사용해 주세요.swal({options})대신.

또한 npm을 사용하는 경우 대문자 S로 Import하십시오.

import Swal from 'sweetalert2'

언급URL : https://stackoverflow.com/questions/58892379/referenceerror-swal-is-not-defined

반응형