简体   繁体   English

如何自定义 Web 组件“height:100%”页面?

[英]How to make a custom Web Component “height:100%” of the page?

I wrote a Web Component using Vue.js and vue-custom-element .我使用 Vue.js 和vue-custom-element编写了一个Web 组件 Now I want to make my-chat and my-whiteboard Web Components "height:100%".I'm using the component like this:现在我想让我的聊天我的白板Web 组件“高度:100%”。我正在使用这样的组件:

// App.vue
<template>
  <splitpanes class="default-theme">
    <pane>
      <my-chat></my-chat>
    </pane>
    <pane>
      <my-whiteboard></my-whiteboard>
    </pane>
  </splitpanes>
</template>

The only way that I know is to set the height of all parents to 100% like this:我知道的唯一方法是将所有父母的身高设置为 100%,如下所示:

html,
body,
splitpanes,
pane,
my-chat,
my-whiteboard {
    height: 100%;
}
//main.js

...
// Load custom element plugin
Vue.use(vueCustomElement);

// Define web components
Vue.customElement("skyroom-whiteboard", Whiteboard);
Vue.customElement("skyroom-chat", Chat);
...

And do this for the all tags inside web my-chat and my-whiteboard too!!!并对 web my-chatmy-whiteboard中的所有标签执行此操作!!!

The problems:问题:

  1. This is not working for my- components.这不适用于my-组件。
  2. It seems to be wrong!好像错了! Isn't there any right way to do this?没有任何正确的方法可以做到这一点吗?

The simple way to do it is to use简单的方法是使用

my-chat, my-whiteboard {
  min-height: 100vh;
}

However, when one of them becomes taller than 100vh, it will grow without the other one.但是,当其中一个变得高于 100vh 时,它会在没有另一个的情况下增长。 So, most likely, ...所以,很可能,...

display: block;
height: 100vh;
overflow-y: auto;

... will do a better job. ...会做得更好。

Here's an example (you don't need any the CSS after /* let's test it */ line but I had to add it as all of them are custom elements and, by default, they have a display value of inline ):这是一个示例(在/* let's test it */行之后不需要任何 CSS 但我必须添加它,因为它们都是自定义元素,默认情况下,它们的display值为inline ):

 my-chat, my-whiteboard { display: block; height: 100vh; overflow-y: auto; } /* let's check it */ my-chat, my-whiteboard { box-sizing: border-box; } tester { height: 200vh; padding: 1rem; } splitpanes { display: flex; } pane:first-child { flex-basis: 75%; } pane:last-child { flex-grow: 1; } body { margin: 0; } /* don't use this line in your app, it will likely break stuff * I used it here because I don't have any content to break. */:default-theme * { display; block; }
 <splitpanes class="default-theme"> <pane> <my-chat> <tester>my-chat</tester> </my-chat> </pane> <pane> <my-whiteboard> <tester>my-whiteboard</tester> </my-whiteboard> </pane> </splitpanes>

Important note: If any of your components gets parsed by Vue into actual <div> elements, you'll need to change the selectors accordingly (but you did say they're custom elements, so I'm guessing they're used as-is).重要提示:如果您的任何组件被 Vue 解析为实际的<div>元素,您需要相应地更改选择器(但您确实说它们是自定义元素,所以我猜它们被用作 -是)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM