首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否可以使用vue -甜警报2 html作为vue组件?

是否可以使用vue -甜警报2 html作为vue组件?
EN

Stack Overflow用户
提问于 2018-11-23 14:59:17
回答 1查看 1.2K关注 0票数 0

我使用这个包https://www.npmjs.com/package/vue-sweetalert2,并希望将Vue.swal中的vue组件作为html使用。

代码语言:javascript
复制
<template>
    <div class="w-full">
        <div class="py-6 w-full">
            <button
                type="button"
                class="btn btn-default btn-primary"
                @click="openTeamsModal"
            >
                Teams
            </button>
        </div>
    </div>
</template>

<script>

import Vue from 'vue';
import TeamTable from "./TeamTable";
import VueSweetalert2 from 'vue-sweetalert2'; 
Vue.use(VueSweetalert2);

export default {
    components: {TeamTable},

    props: [
        'resourceName',
        'resourceId',
        'field'
    ],

    data: () => ({
        teams: [],
    }),

    methods: {

        openTeamsModal() {

            Nova.request().get(`/api/competitors/${this.field.seasonId}/${this.field.championshipId}`).then( responce  => {
                console.log(responce)
            });

            Vue.swal({
                title: 'Test',
                html: '<team-table></team-table>',
            });
        }

    },
}
</script>

但什么都没有。我是VueJ的新手,我仍然不完全理解如何将我的组件插入到html中。

EN

回答 1

Stack Overflow用户

发布于 2019-08-28 13:46:03

是!有可能!.经过几个小时的研究,我已经成功了。

这是一种方法:

您需要在这个字符之间包含模板的所有逻辑。

您还需要编辑vue.config.js文件,并在配置will对象中添加以下内容:'vue$':'vue/dist/vue.esm.js‘

代码语言:javascript
复制
configureWebpack: {
  resolve: {
    alias: {
      'src': resolveSrc('src'),
      'chart.js': 'chart.js/dist/Chart.js',

      // add this line for include components inside swal alert
      'vue$':'vue/dist/vue.esm.js'
    }

一旦完成,您必须重新启动"npm运行dev“项目。

这是我的完整示例,经过测试和工作。

代码语言:javascript
复制
openSweet() {
      Vue.component('my-comp', {
          template: `
                <div class="card-content">
                  <div class="span2">
                        <div class="col-sm-6 col-md-2 col-lg-3">
                            <div class="row">
                              <div style="margin-top: 6px;" >
                                <p-switch v-model="switchTrip.state" type="primary" on-text="ON" off-text="OFF" style="justify-content:center"></p-switch>
                                <h5 class="card-title" style="margin-left: 25px;">Recorridos</h5>
                              </div>
                            </div>

                            <div class="row">
                              <div style="margin-top: 6px;" >
                                <p-switch v-model="switchVel.state" type="primary" on-text="ON" off-text="OFF" style="justify-content:center"></p-switch>
                                <h5 class="card-title" style="margin-left: 25px;">Velocidad</h5>
                              </div>
                            </div>

                        </div>
                  </div>
                  <div class="span2">
                        <div class="col-sm-6 col-md-4 col-lg-3">
                            <div class="row">
                              <div >
                                <input type="search" class="form-control input-sm" placeholder="km / h" v-model="vmax">
                                <h5 class="card-title">Vel. Max</h5>
                              </div>
                            </div>

                            <div class="row">
                              <div>
                                <input type="search" class="form-control input-sm" placeholder="minutos" v-model="tol">
                                <h5 class="card-title">Tolerancia</h5>
                              </div>
                            </div>
                        </div>
                  </div>
                </div>
          `,
        data () {
          return {
            switchVel: {
              state: false
            },
            switchEvent: {
              state: false
            },
            switchTrip: {
              state: false
            },
            search: '',
            vmax: '',
            tol: ''
          }
        },
        components: {
            [Button.name]: Button,
            Card,
            PSwitch
        }
      })
      new Vue({
        el: '#modal',
        beforeCreate:  () => {
          swal({
            titleText: "Descarga de Reportes",
            showCancelButton: true,
            cancelButtonText: 'Cancelar',
            confirmButtonText: 'Descargar',
            // confirmButtonAriaLabel: 'glyphicon glyphicon-ok-sign',
            // cancelButtonAriaLabel: 'glyphicon glyphicon-remove-sign',
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            width: 800,
            html: '<div id="modal"><my-comp></my-comp></div>'
          })
        }
      })
    }

我希望它能帮到你

阿根廷的问候

https://github.com/aledc7

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53448935

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档