首页 > 解决方案 > ie11 上的 sl-vue-tree + vue-cli3.1

问题描述

我是日本人,我不擅长英语对不起。

我正在使用 vue-cli3.1。

我想在 ie11 上使用这个模块。 https://github.com/holiber/sl-vue-tree

它说你可以在 ie11 上使用 babel-polyfil。

但我不能正确使用 babel-polyfil。

我做了“纱线添加@babel/polyfill”。

我在 main.ts 的顶部导入了它。

但它没有用。

import "@babel/polyfill"

import Vue from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';

Vue.config.productionTip = false;

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount('#app');

<template>
  <div class="about">
    <h1>This is an about page</h1>
    <SlVueTree v-model="treeModel">

    </SlVueTree>
  </div>
</template>
<script lang="ts">
import { Component, Vue } from "vue-property-decorator";

//sl-vue-tree
import SlVueTree from "sl-vue-tree-original";


@Component({
  components: {
    SlVueTree
  }
})
export default class About extends Vue {

  public treeModel = [
    {
        "title": "Item1",
        "isLeaf": true
    },
    {
        "title": "Item2",
        "isLeaf": true
    },
    {
        "title": "Folder1",
        "isExpanded": true,
        "children": [
            {
                "title": "Item3",
                "isLeaf": true
            },
            {
                "title": "Item4",
                "isLeaf": true
            },
            {
                "title": "Folder2",
                "children": [
                    {
                        "title": "Item5",
                        "isLeaf": true
                    }
                ]
            }
        ],
        "isSelected": true
    },
    {
        "title": "Item6",
        "isLeaf": true
    }
];

  }
}
</script>

标签: javascripttypescriptvue.jsecmascript-6babel-polyfill

解决方案


这就是我解决它的方法。我正在使用 Vue cli 3.6 和 sl-vue-tree 1.8.4

将 transpileDependencies 添加到 vue.config.js

module.exports = {
 transpileDependencies: ['sl-vue-tree'],
 ...
}

我的 babel.config.js

module.exports = {
 presets: [
  ["@vue/app", {
    modules: "commonjs"
  }]
 ]
};

在我的 vue 组件中,我只是像这样导入 sl-vue-tree:

import slVueTree from "sl-vue-tree";

推荐阅读