Uncaught TypeError: $(...).swipeout is not a function

問題:

在使用weui的滑塊刪除組件的時候,有時候會出現這種錯誤

Uncaught TypeError: $(…).swipeout is not a function

原因是在引用weui的時候,也引用了jquery,並且jquery引用在這段代碼的前面,造成衝突

$('.delete-swipeout').click(function() {
   $(this).parents('.weui-cell').remove()
   console.log(123)
})
$('.close-swipeout').click(function() {
   $(this).parents('.weui-cell').swipeout('close')
   console.log(456)
})
$('.weui-cell_swiped').swipeout('open')//就是這裏報錯
$(document).on("swipeout-open", '.weui-cell_swiped', function() {
   //監聽打開觸發
   console.log(788)
})
$(document).on("swipeout-close", '.weui-cell_swiped', function() {
   //監聽關閉觸發
   console.log(1212)
})

解決辦法:

將jquery引用放到上面那段代碼後面

<script type="text/javascript">
        $('.delete-swipeout').click(function() {
            $(this).parents('.weui-cell').remove()
            console.log(123)
        })
         $('.close-swipeout').click(function() {
            $(this).parents('.weui-cell').swipeout('close')
            console.log(456)
        })
         $('.weui-cell_swiped').swipeout('open')
        $(document).on("swipeout-open", '.weui-cell_swiped', function() {
            //監聽打開觸發
            console.log(788)
        })
        $(document).on("swipeout-close", '.weui-cell_swiped', function() {
            //監聽關閉觸發
            console.log(1212)
        })
    </script>
    <script src="js/jquery.js"></script><!-- 引用在後面 -->
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章