【问题标题】:How can I use jquery in response ajax vue.js 2?如何使用 jquery 响应 ajax vue.js 2?
【发布时间】:2017-11-08 22:41:58
【问题描述】:

我的组件vue是这样的:

<script>
    export default {
        ...
        methods: {
            deleteImageProduct(event) {
                const payload = {id: this.productId}
                const data = this.$store.dispatch('deleteProduct', payload);
                data.then((res) => 
                    $('#test').remove();
                )
            }
        } 
    }
</script>

执行时,在 gulp watch 上存在错误:

模块构建失败:SyntaxError: Unexpected token

并且在控制台上存在错误:

Uncaught ReferenceError: jQuery is not defined

我使用jquery是因为被调用的div在视图中或者不在vue组件中

我该如何解决这个问题?

【问题讨论】:

    标签: javascript jquery laravel-5.3 vuejs2 vue-component


    【解决方案1】:

    你应该导入 jquery 库以便你可以使用它。

    import $ from 'jquery'
    

    更多信息在这里:https://www.npmjs.com/package/jquery

    【讨论】:

      猜你喜欢
      • 2017-06-12
      • 2021-10-28
      • 1970-01-01
      • 2011-01-21
      • 1970-01-01
      • 2013-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多