我在计算插槽的高度和宽度时遇到问题。我正在尝试在我的 Perimeter 组件中渲染图像。这些图像的大小为 105x160。但是,当我 console.log clientWidth 和 clientHeight 时,我得到 0x24。
我相信我的问题与此有关:在 vue.js 2 中,在渲染插槽后测量组件的高度,但我仍然无法弄清楚。我已经尝试在 Perimeter 组件和单个插槽组件上使用 $nextTick 。
在我的 Perimeter 组件中,我有:
<template>
<div class="d-flex">
<slot></slot>
<div class="align-self-center">
<slot name="center-piece"></slot>
</div>
</div>
</template>
<script>
export default {
name: 'Perimeter',
mounted() {
this.distributeSlots();
},
updated() {
this.distributeSlots();
},
computed: {
centerRadius() {
return this.$slots['center-piece'][0].elm.clientWidth / 2;
},
},
methods: {
distributeSlots() {
let angle = 0;
const {
clientHeight: componentHeight,
clientWidth: componentWidth,
offsetTop: componentOffsetTop,
offsetLeft: componentOffsetLeft,
} = this.$el;
const …Run Code Online (Sandbox Code Playgroud) 我正在使用用 TypeScript 编写的 Angular 2 编写一个简单的 Web 应用程序。MongoDB 是我在 Mongoose 框架上的数据库,同时在 Express 框架上的 Node 服务器上运行。我的 MongoDB 和 Node 代码是用 vanilla JS 编写的。
现在,我为一个国家创建了一个 Mongoose 模型,如下所示:
"use strict";
const Schema = require('mongoose').Schema,
db = require('../../config/database');
let countrySchema = new Schema({
countryName: { type: String, index : { unique : true } }
});
let Country = db.model('Country', countrySchema);
module.exports = Country;
Run Code Online (Sandbox Code Playgroud)
现在,Country 是我想要的对象。在我的应用程序组件中,我有:
import { Component } from '@angular/core';
import { CountryService } from '../services/country.service';
import { Country } from '../models/country.model'; …Run Code Online (Sandbox Code Playgroud) 有没有办法在Vue组件中设置插槽的样式?
<slot style="position: absolute"></slot>
Run Code Online (Sandbox Code Playgroud)
和
<slot class="slot"></slot>
Run Code Online (Sandbox Code Playgroud)
不工作.
vue.js ×2
vuejs2 ×2
angular ×1
angularjs ×1
dom ×1
javascript ×1
mongodb ×1
node.js ×1
typescript ×1