代码之家  ›  专栏  ›  技术社区  ›  niko craft

vue2网站上的以下教程无法让第三方jquery插件select2正常工作

  •  1
  • niko craft  · 技术社区  · 8 年前

    https://v2.vuejs.org/v2/examples/select2.html

    虽然我在页面中使用Vue组件,但我并没有制作SPA。

    我得到这个错误

    Error in mounted hook: "TypeError: $(...).select2 is not a function"
    
    found in <Select2> at 
    C:\laragon\www\lara\resources\assets\js\components\ui\Select2.vue
    

    我在html文件中包括select2和我的VUEJ:

    <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
    <script src="{{ asset('js/content_type_blocks.js') }}?{{ str_random(7) }}"></script>
    

    我想知道为什么我会得到错误,select2不是一个函数?

    1 回复  |  直到 3 年前
        1
  •  4
  •   Greg C.    8 年前

    在Select2插件初始化时,jquery尚未加载到全局堆栈中。


    提出几种解决方案:

    推荐文章