【问题标题】:How to use trading-vue library with vanilla html and vue cdn如何在 vanilla html 和 vue cdn 中使用 trading-vue 库
【发布时间】:2021-03-13 08:13:29
【问题描述】:
<html>
<head>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.12/dist/vue.js"></script>
    <script src =  './libs/trading-vue-js-master/dist/trading-vue.js' ></script>

</head>
<body>
    <div id = "app"></div>

    <test>
    </test>
<script>
    var app2 = new Vue({
        name: 'app',
    })
   
    app2.use(xxxMAYBESOMETHINGLIKETHIS?xxxxx)
</script>
</body>
</html>

我想将 trading-vue 库与我从 Vue cdn 导入的 Vue 一起使用。我该怎么做?谢谢。

【问题讨论】:

    标签: javascript html vue.js vuejs2 vue-component


    【解决方案1】:

    首先确保您拥有trading-vue 的有效 CDN(因为您需要 CDN),例如:

    <script src="https://cdn.jsdelivr.net/npm/trading-vue-js@0.9.0/dist/trading-vue.min.js"></script>
    

    无论你想在哪里使用它,在父级的components 选项中注册组件定义:

    components: {
      trading: TradingVueJs.TradingVue  // Naming it 'trading'
    }
    

    给父母一些数据:

    data() {
      return {
        mydata: {
          ohlcv: [  // Taken from their docs, this name seems to be important
            [ 1551128400000, 33,  37.1, 14,  14,  196 ],
            [ 1551132000000, 13.7, 30, 6.6,  30,  206 ],
            [ 1551135600000, 29.9, 33, 21.3, 21.8, 74 ],
            [ 1551139200000, 21.7, 25.9, 18, 24,  140 ],
            [ 1551142800000, 24.1, 24.1, 24, 24.1, 29 ],
          ]
        }
      }
    },
    

    将该数据作为道具传递:

    <div id="app">
      <trading :data="mydata"></trading>
    </div>
    

    这是一个演示:

    /***** APP *****/
    new Vue({
      el: "#app",
      data() {
        return {
          mydata: {
            ohlcv: [
              [ 1551128400000, 33,  37.1, 14,  14,  196 ],
              [ 1551132000000, 13.7, 30, 6.6,  30,  206 ],
              [ 1551135600000, 29.9, 33, 21.3, 21.8, 74 ],
              [ 1551139200000, 21.7, 25.9, 18, 24,  140 ],
              [ 1551142800000, 24.1, 24.1, 24, 24.1, 29 ],
            ]
          }
        }
      },
      components: {
        trading: TradingVueJs.TradingVue
      }
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
    <div id="app">
      <trading :data="mydata"></trading>
    </div>
    
    <script src="https://cdn.jsdelivr.net/npm/trading-vue-js@0.9.0/dist/trading-vue.min.js"></script>

    【讨论】:

      猜你喜欢
      • 2021-05-03
      • 1970-01-01
      • 2020-03-11
      • 2021-12-10
      • 1970-01-01
      • 2020-04-25
      • 2021-06-08
      • 2020-11-29
      • 2018-05-19
      相关资源
      最近更新 更多