thankseveryday
2019-05-22 21:07
采纳率: 0%
浏览 4.7k
已结题

Vue CLI 如何引入第三方js文件

第三方库:
https://github.com/google/blockly
需要引入两个js文件
blockly_compressed.js
blocks_compressed.js
使下边的代码正常运行

<template>
    <div id="lesson1">
        <h1>挑战1</h1>
        <hr>
        <div id="blocklyDiv" style="height: 480px; width: 600px;"></div>
        <xml id="toolbox" style="display: none">
            <block type="controls_if"></block>
            <block type="logic_compare"></block>
            <block type="controls_repeat_ext"></block>
            <block type="math_number">
                <field name="NUM">123</field>
            </block>
            <block type="math_arithmetic"></block>
            <block type="text"></block>
            <block type="text_print"></block>
        </xml>
    </div>
</template>

<script>
    Vue.use(Blocks)
    var workspace = Blockly.inject('blocklyDiv', {
        toolbox: document.getElementById('toolbox')
    });
</script>

@oyljerry

这样还是不行

<template>
    <div id="lesson1">
        <h1>挑战1</h1>
        <hr>
        <div id="blocklyDiv" style="height: 480px; width: 600px;"></div>
        <xml id="toolbox" style="display: none">
            <block type="controls_if"></block>
            <block type="logic_compare"></block>
            <block type="controls_repeat_ext"></block>
            <block type="math_number">
                <field name="NUM">123</field>
            </block>
            <block type="math_arithmetic"></block>
            <block type="text"></block>
            <block type="text_print"></block>
        </xml>
    </div>
</template>

<script>
    import Blockly from '../../public/blockly_compressed.js'
    Vue.use(Blockly)
    import Blocks from '../../public/blocks_compressed.js'
    Vue.use(Blocks)

    var workspace = Blockly.inject('blocklyDiv', {
        toolbox: document.getElementById('toolbox')
    });
</script>
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题