2017-10-03 9 views
2

これを間違ってインポートする必要があると思われますが、わかりません。私はgithubの指示に従った。それは私がnpm installそれをすることができ、次にちょうどimport swal from 'sweetalert2'ことができると言います。 jscssファイルも使用する必要がありますか?アラートがスローされたときにスウィートアラート2がモーダルとして表示されない

私の窓の左下には逃げない奇妙な警告が表示されます。あなたはCSSファイル含める必要があり

import React, { Component } from 'react'; 
import swal from 'sweetalert2'; 

class TestSwal extends Component { 
    componentDidMount() { 
    swal({ 
     title: 'Are you sure?', 
     text: 'You will not be able to recover this imaginary file!', 
     type: 'warning', 
     showCancelButton: true, 
     confirmButtonText: 'Yes, delete it!', 
     cancelButtonText: 'No, keep it' 
    }).then(
     function() { 
     swal('Deleted!', 'Your imaginary file has been deleted.', 'success'); 
     }, 
     function(dismiss) { 
     // dismiss can be 'overlay', 'cancel', 'close', 'esc', 'timer' 
     if (dismiss === 'cancel') { 
      swal('Cancelled', 'Your imaginary file is safe :)', 'error'); 
     } 
     } 
    ); 
    } 
    render() { 
    return <div>Test Swal</div>; 
    } 
} 

export default TestSwal; 

答えて

1

アップデート(2017年1月):あなたはJSとCSSの両方をインポートする必要があるすべてのV7から始まっです:私たちは最近、JSでオールインワンのバージョンが含まれているv6.10.0をリリース

import swal from 'sweetalert2' 

1つの場所でCSSを使用できます。

あなたは、このようにそれをインポートすることができます。

import swal from 'sweetalert2/dist/sweetalert2.all.min.js' 
+0

ここに新しいリリースの使用例があります:https://github.com/limonte/sweetalert2-webpack-demo#indexjs –

4

import 'sweetalert2/dist/sweetalert2.min.css'; 

のかUsage section on Githubに示すように、HTMLファイルにCDNのバージョンが含まれenter image description here

は、ここに私のコードです。

+0

は、これが働いたありがとう! –

関連する問題