在vuejs组件中调用外部函数

时间:2018-04-13 09:13:58

标签: javascript vue.js vue-component

我想使用jsgrid.min.js在vue组件中创建表。我应该在jsgrid.min.jsfunction中调用它

jsGrid(..)

我该怎么做?(调用将vue组件放在组件外部的函数)

component.vue

<template>
    <div id="jsGrid">

    </div>
</template>

<script>
    export default {
        data: () => ({
        name: "mja"
    }),


    mounted () {

        $("#jsGrid").jsGrid({
            width: "100%",
            height: "500px"

            });

    }
    }
</script>

<style scoped>

</style>

错误

  

[Vue警告]:挂钩错误:&#34; TypeError:$(...)。jsGrid不是函数&#34;

我实际嵌入了src文件

<script type="text/javascript" src="{{ asset('plugins/jsgrid/dist/jsgrid.min.js')}}"></script>

1 个答案:

答案 0 :(得分:1)

你需要使用Jquery将Jquery包含为jsGrid,这是工作演示:)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.css" />
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid-theme.min.css" />
 
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/vue"></script>

<div id="app">
 {{ message }}
<div id="jsGrid"></div>
</div>
List<android.util.Size> resolutions = Arrays.asList(map.getOutputSizes(MediaRecorder.class));