小镇女孩

文章 评论 浏览 31

小镇女孩 2025-02-21 02:18:29

您可以尝试 pinput ,或检查他们的实现并尝试制作自己的实现。

you can try pinput, or check their implementation and try to make your own one.

发送多个控制器作为一个控制器

小镇女孩 2025-02-20 17:25:16

简短答案:

“

最快的解决方案是将VS代码终端从PowerShell切换到CMD。

在下拉下,选择CMD。

长答案:

只需在Powershell中设置路径即可。

打开PowerShell并将其作为管理员运行。
运行此代码:(复制,粘贴从这里)

[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Program Files\Python35-32")“

注意:在这里,在路径中,添加您在系统中安装Python的路径,在我的情况下,它是“ C:\ Program Files \ Python35-32”。

它必须解决了错误。

要确认,请运行此代码:

“python --version”

Short Answer:

VS code cmd

Fastest solution is to switch the vs code terminal from Powershell to Cmd.

On the drop-down there choose Cmd.

Long Answer:

Just set the path in the powershell.

Open Powershell and run it as an admin.
Run this code: (copy, paste from here)

[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Program Files\Python35-32")“

Note: Here, in Path, add the path where you’ve installed Python in your system, here in my case it is “C:\Program Files\Python35-32”.

It must have resolved the error.

To confirm, run this code:

“python --version”

我似乎可以在VS代码中运行我的Python代码

小镇女孩 2025-02-19 22:05:49

通常,这些是只有一张记录(一种类型的保险)的成员:

SELECT 
    member,
    COUNT(member) as total
FROM Table 
GROUP BY member
HAVING COUNT(member) = 1;

这里的想法是,如果成员有一种保险,您会看到一张记录,因此计数为(1),但是如果成员有两种类型的保险,它们有两个记录,因此该成员的计数为(2),依此类推。

接下来,要更详细地看到它们,因为您现在知道您感兴趣的成员,只需使用该结果集再次加入原始表:

SELECT A.*
FROM Table A
INNER JOIN  
(
    SELECT 
        member,
        COUNT(member) as total
    FROM Table 
    GROUP BY member
    HAVING COUNT(member) = 1
) B
ON A.member = B.member;

因此,现在您可以看到这些成员的详细信息(保险类型)。

现在,您说:“ B专栏具有显然包含重复项的保险类型。” ...这还不清楚,但是如果您的意思是这一点,那么您将不得不删除重复项,因此,与上面相同但使用更多数据清洁。例如,如果您的数据具有一个针对DTH类型的一行和TPD类型的两行的成员,则需要这是需要的,因此我们希望对(2)的该成员进行计数,而不是(3)!

SELECT 
    X.member,
    COUNT(X.member) as total
FROM (SELECT DISTINCT member, type FROM Table) X
GROUP BY X.member
HAVING COUNT(X.member) = 1;

对于同一版本的完整版本:

SELECT DISTINCT A.*
FROM Table A
INNER JOIN  
(
    SELECT 
        X.member,
        COUNT(X.member) as total
        FROM (SELECT DISTINCT member, type from Table) X
        GROUP BY X.Member
        HAVING COUNT(X.member) = 1
) B
ON A.member = B.member

In general these are the members with only one record (one type of insurance):

SELECT 
    member,
    COUNT(member) as total
FROM Table 
GROUP BY member
HAVING COUNT(member) = 1;

The idea here is that if a member has one type of insurance, you see one record so count is (1) for that member, but if a member has two types of insurance, they have two records, so count is (2) for that member, and so on.

Next, to see them in more detail, since you now know the members you are interested in, just join back to the original table again using that result set:

SELECT A.*
FROM Table A
INNER JOIN  
(
    SELECT 
        member,
        COUNT(member) as total
    FROM Table 
    GROUP BY member
    HAVING COUNT(member) = 1
) B
ON A.member = B.member;

so now you can see the details (insurance types) for those members.

Now, you said "Column B has the type of insurance which obviously contains duplicates." ... this is a little unclear, but if you really mean this then you will have to remove the duplicates, so, same as above but with more data cleaning. This would be needed, for instance, if your data has a member with one row for type DTH and two rows for type TPD, so we want to have a count for that member of (2), not (3)!

SELECT 
    X.member,
    COUNT(X.member) as total
FROM (SELECT DISTINCT member, type FROM Table) X
GROUP BY X.member
HAVING COUNT(X.member) = 1;

and for the fuller version of the same:

SELECT DISTINCT A.*
FROM Table A
INNER JOIN  
(
    SELECT 
        X.member,
        COUNT(X.member) as total
        FROM (SELECT DISTINCT member, type from Table) X
        GROUP BY X.Member
        HAVING COUNT(X.member) = 1
) B
ON A.member = B.member

sql-在许多到许多表中找到一个独特的1-1关系值

小镇女孩 2025-02-18 16:11:21

您可以尝试以下方法将.docx文件转换为.pdf文件。

https://simples.dev/simples.dev/java-convert -docx-file-to-pdf-file-using-xdocReport/

import fr.opensagres.poi.xwpf.converter.pdf.PdfConverter;
import fr.opensagres.poi.xwpf.converter.pdf.PdfOptions;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;

public class FileConverter {

    public void convertWordToPdf(String docxFileName, String pdfFileName) {
        try(InputStream inputStream = new FileInputStream(docxFileName);
            OutputStream outputStream = new FileOutputStream(pdfFileName)) {
            XWPFDocument document = new XWPFDocument(inputStream);
            PdfOptions options = PdfOptions.create();
            // Convert .docx file to .pdf file
            PdfConverter.getInstance().convert(document, outputStream, options);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
String docxFileName = "D:\\SimpleSolution\\Data\\Document.docx";
String pdfFileName = "D:\\SimpleSolution\\Data\\Document.pdf";

FileConverter fileConverter = new FileConverter();
fileConverter.convertWordToPdf(docxFileName, pdfFileName);

You can try the following approach to convert a .docx file to .pdf file.

https://simplesolution.dev/java-convert-docx-file-to-pdf-file-using-xdocreport/

import fr.opensagres.poi.xwpf.converter.pdf.PdfConverter;
import fr.opensagres.poi.xwpf.converter.pdf.PdfOptions;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;

public class FileConverter {

    public void convertWordToPdf(String docxFileName, String pdfFileName) {
        try(InputStream inputStream = new FileInputStream(docxFileName);
            OutputStream outputStream = new FileOutputStream(pdfFileName)) {
            XWPFDocument document = new XWPFDocument(inputStream);
            PdfOptions options = PdfOptions.create();
            // Convert .docx file to .pdf file
            PdfConverter.getInstance().convert(document, outputStream, options);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
String docxFileName = "D:\\SimpleSolution\\Data\\Document.docx";
String pdfFileName = "D:\\SimpleSolution\\Data\\Document.pdf";

FileConverter fileConverter = new FileConverter();
fileConverter.convertWordToPdf(docxFileName, pdfFileName);

如何将DOCX转换为PDF使用Java(韩国)

小镇女孩 2025-02-18 07:07:37

您是否考虑过使用垂直线和水平线创建新图像,比原始图像略高略高,更宽,您粘贴了原始图像?
这样,您将有一个虚线的边框,并且适用于各种尺寸。

这可以如下所述完成:

from PIL import Image,ImageDraw
#this is your own image
yourimage = Image.open('/home/vancha/Documenten/python/pillu/square.png', 'r')
img_w, img_h = yourimage.size
border_width = 5
#this is the new image which holds the stripes
borderimage = Image.new('RGBA', (2000+(border_width * 2), 2000+(border_width *2)), (255, 255, 255, 255))


# Draw the lines
draw = ImageDraw.Draw(borderimage)
#starts drawing vertical lines form the very top
start = 0
end = borderimage.height#width or height, doens't matter since the image is square
step_size = border_width*4

#starts from border_width * 2, so that the very top and very left aren't made black with lines
for x in range(border_width*2, borderimage.width, step_size):
    vertical_line = ((x, start), (x, end))
    #the width is the thickness of the "dots" in the border
    draw.line(vertical_line, fill=(0,0,0),width=border_width * 2)

    horizontal_line = ((start,x), (end, x))
    draw.line(horizontal_line, fill=(0,0,0),width=border_width *2)

#for good practice:
del draw


bg_w, bg_h = borderimage.size
#calculate the offset so that the image is centered
offset = ((bg_w - img_w) // 2, (bg_h - img_h) // 2)

#paste your old image over the one with the dots
borderimage.paste(yourimage, offset)

#save it wherever you want :)
borderimage.save('./border.png')

“>在您的情况下, 如果您将自己的图像粘贴在中心,则在2010年将是2010年的新图像,使您在两边都有5px。

Have you considered creating a new image with vertical lines as well as horizontal lines, slightly taller and wider than your original image, on which you paste your original image?
That way you will have a dotted border and it works for every size.

This can be done as explained here: How do you composite an image onto another image with PIL in Python?

from PIL import Image,ImageDraw
#this is your own image
yourimage = Image.open('/home/vancha/Documenten/python/pillu/square.png', 'r')
img_w, img_h = yourimage.size
border_width = 5
#this is the new image which holds the stripes
borderimage = Image.new('RGBA', (2000+(border_width * 2), 2000+(border_width *2)), (255, 255, 255, 255))


# Draw the lines
draw = ImageDraw.Draw(borderimage)
#starts drawing vertical lines form the very top
start = 0
end = borderimage.height#width or height, doens't matter since the image is square
step_size = border_width*4

#starts from border_width * 2, so that the very top and very left aren't made black with lines
for x in range(border_width*2, borderimage.width, step_size):
    vertical_line = ((x, start), (x, end))
    #the width is the thickness of the "dots" in the border
    draw.line(vertical_line, fill=(0,0,0),width=border_width * 2)

    horizontal_line = ((start,x), (end, x))
    draw.line(horizontal_line, fill=(0,0,0),width=border_width *2)

#for good practice:
del draw


bg_w, bg_h = borderimage.size
#calculate the offset so that the image is centered
offset = ((bg_w - img_w) // 2, (bg_h - img_h) // 2)

#paste your old image over the one with the dots
borderimage.paste(yourimage, offset)

#save it wherever you want :)
borderimage.save('./border.png')

In your case, if you want your border to be 5px all the way around your image, and your image is 2000,2000, changing the size of the new image to be 2010 by 2010 leaves you with 5px to spare on both sides if you paste your own image in the center.

如何将点或虚线添加到Python中的PNG?

小镇女孩 2025-02-17 13:06:25

假设您正在使用Tokio,请致电Tokio :: Spawn并不一定保证任务将在单独的线程上执行(尽管可能是)。

这里的问题是std :: thread :: sleep()完全阻止了任务正在运行的线程,这意味着您的ping会异步运行(不是阻止其他任务),但是当您继续进入当前的睡眠时,线程将执行接下来的4秒。

您可以使用非阻止版本的睡眠版本,例如Tokio https://docs.rs/tokio/latest/tokio/time/time/ftime/fn.sleep.html

因此,您的代码看起来像是


 pub fn sending_ping(addr: Addr<MicroscopeClient>) -> Result<(), ()> {
    info!("Pings started");

    spawn(async move {
        loop {
            info!("Ping");
            match addr.send(Ping {}).await {
                Ok(_) => {
                    info!("Ping sended")
                }
                Err(e) => {
                    warn!("Ping error");
                    return;
                }
            }
            tokio::time::sleep(Duration::from_millis(4000)).await;
        }
    });
    return Ok(());
}

您确实想确保任务在另一个线程上散发出来您必须使用 std :: thread :: Spret :: Spawn 但是,您将不得不设置另一个异步运行时。相反,您可以使用 spawn_blocking 至少保证任务的保证是在期望阻止任务的线程上运行


Assuming you are using tokio, calling tokio::spawn does not necessarily guarantee that the task will be executed on a separate thread (though it may be).

The problem here is that std::thread::sleep() completely blocks the thread that the task is running on, meaning your pings will run asynchronously (not blocking other tasks) but when you move on to the sleep nothing else on the current thread will execute for the next 4 seconds.

You can resolve this by using a non-blocking version of sleep, such as the one provided by tokio https://docs.rs/tokio/latest/tokio/time/fn.sleep.html

Thus your code would look like


 pub fn sending_ping(addr: Addr<MicroscopeClient>) -> Result<(), ()> {
    info!("Pings started");

    spawn(async move {
        loop {
            info!("Ping");
            match addr.send(Ping {}).await {
                Ok(_) => {
                    info!("Ping sended")
                }
                Err(e) => {
                    warn!("Ping error");
                    return;
                }
            }
            tokio::time::sleep(Duration::from_millis(4000)).await;
        }
    });
    return Ok(());
}

If you truly want to ensure that the task spawns on a different thread you would have to use std::thread::spawn but you would then have to set up another async runtime. Instead you could use spawn_blocking which at least guarantees the task is run on a thread where tasks are expected to block


如何创建用于在客户端WebScoket上发送ping的单个线程

小镇女孩 2025-02-17 06:39:28

检查您的Discord版本。如果它小于2.0.0,则可能需要导入旧的Discord-Py-slash-commands。这些是对我有用的版本:

    discord==1.7.3
    discord-py-slash-command==2.0.0
    discord.py==1.7.3

check your discord version. If it's less than 2.0.0 then you might need to import an older discord-py-slash-commands. These are the versions that worked for me:

    discord==1.7.3
    discord-py-slash-command==2.0.0
    discord.py==1.7.3

Discord-py-slash-command命令导入问题,不能使用discord_slash

小镇女孩 2025-02-17 05:44:12

Vnode对象不能像modrender这样的组件中呈现在组件模板中。如果它们被用作通用方式来交换应用程序中的模板数据,那是一个问题。 Vnodes仍然可以直接用于组件渲染函数和功能组件,具有JSX或H喜欢&lt; layout&gt; {rendermodule(state)}&lt;/layout;/layout&gt;,这限制他们的用法。

AbstractModule如果会导致不必要的代码,则可能需要重新考虑约定。从某个时候,需要与动态&gt;一起使用“视图”的事实,并且它将尽可能简单地使用。

可能没有必要进行“模块”抽象,但是即使存在,module.view也可以返回组件(功能或状态)而不是vnodes。或者它可以构建一个组件并使其作为属性可用,例如:

class MyModule {
  constructor(state) {
    this.viewComponent = (props) => h(ModuleView, { state, ...props })
  }
}

Vnode objects cannot be rendered in component templates as is and need to be wrapped in a component like ModRender. If they are used as universal way to exchange template data in the app, that's a problem. Vnodes still can be directly used in component render functions and functional components with JSX or h like <Layout>{renderModule(state)}</Layout>, this limits their usage.

AbstractModule convention may need to be reconsidered if it results in unnecessary code. Proceed from the fact that a "view" needs to be used with dynamic <component> at some point, and it will be as straightforward as possible.

There may be no necessity for "module" abstraction, but even if there is, module.view can return a component (functional or stateful) instead of vnodes. Or it can construct a component and make it available as a property, e.g.:

class MyModule {
  constructor(state) {
    this.viewComponent = (props) => h(ModuleView, { state, ...props })
  }
}

是否有A&#x27; Simple&#x27;在Vue中动态渲染视图的方法?

小镇女孩 2025-02-17 00:32:08

父项目已经可用,只需重命名对其的引用即可防止两个“项目”,一个是父,一个是孩子,请参考正确的内容。

    <v-data-table
  :headers="headers"
  :items="financialDocuments"
  :single-expand="singleExpand"
  item-key="finDocId"
  show-expand
>
  <template v-slot:expanded-item="{ item: finDoc }">
    <td :colspan="attachmentHeaders.length">
      <v-data-table
        :headers="attachmentHeaders"
        :items="finDoc.attachmentPlainDtos"
      >
        <template v-slot:[`item.attachmentActions`]="{ item }">
          <v-icon large @click="removeAttachment(finDoc.Id, item.attachmentId)">
            mdi-delete
          </v-icon>
        </template>
      </v-data-table>
    </td>            
  </template>
</v-data-table>

The parent item was already available, just had to rename the reference to it to prevent two "item"s, one is the parent, one is child and refer to the correct one.

    <v-data-table
  :headers="headers"
  :items="financialDocuments"
  :single-expand="singleExpand"
  item-key="finDocId"
  show-expand
>
  <template v-slot:expanded-item="{ item: finDoc }">
    <td :colspan="attachmentHeaders.length">
      <v-data-table
        :headers="attachmentHeaders"
        :items="finDoc.attachmentPlainDtos"
      >
        <template v-slot:[`item.attachmentActions`]="{ item }">
          <v-icon large @click="removeAttachment(finDoc.Id, item.attachmentId)">
            mdi-delete
          </v-icon>
        </template>
      </v-data-table>
    </td>            
  </template>
</v-data-table>

v-data-table父项目数据在扩展的项目插槽中

小镇女孩 2025-02-16 19:15:43

*NGFOR指令用于迭代值数组。 您使用 *ngfor来迭代单个原始值,这就是为什么您要获得此错误type'number'无法分配给'

在您的代码中, 单个值,您可以将NGIF与异步管一起使用

 <div *ngIf="data$ | async as d">{{ d }}</div>

*ngFor directive used for iterating array of values. In your code you were using *ngFor to iterate a single primitive value, that's why you are getting this error Type 'number' is not assignable to type 'NgIterable<any>'.

If you want to get single value you can use ngIf along with async pipe

 <div *ngIf="data$ | async as d">{{ d }}</div>

类型&#x27;数字&#x27;不能分配给类型&#x27; ngiterable&lt; any gt;&#x27;尝试异步观察数据源时

小镇女孩 2025-02-16 16:53:42

有些事情是正确的:

  • 您从不称呼MyBody()
  • MyBody是一个函数,而var
  • rgb则是未定义的
<meta charset="utf-8" />

<html>
  <head>
    <title>Cuadro cambia color // By Abraham Gonzalez</title>
  </head>

  <body id="myBody">
    <canvas id="canvas" width="400" height="400"></canvas>
  </body>

  <script>
    function myBody() {
      var myBodyt = document.getElementById('myBody');
      myBodyt.addEventListener('click', btnRojoClic);
    }

    function btnRojoClic() {
      console.log('clickkeked');
      var canvas = document.getElementById('canvas');
      var ctx = canvas.getContext('2d');
      ctx.fillStyle = "#"+Math.floor(Math.random()*16777215).toString(16);
    }

    myBody();
    var canvas = document.getElementById('canvas');
    var ctx = canvas.getContext('2d');

    var posicion = 0;
    var tamano = 0;

    setInterval(function () {
      ctx.clearRect(0, 0, 400, 400);
      ctx.fillRect(posicion, 0, tamano, tamano);

      posicion++;
      tamano++;

      if (posicion > 400) {
        posicion = 0;
        tamano = 0;
      }
    }, 30);
  </script>
</html>

编辑仅在单击正方形时更改颜色。您不能直接在矩形(FillRect)上添加事件侦听器,但是可以在画布上进行操作。单击时,请检查事件位置(x,y)是否在广场上(checkCollision())。如果是这样,请更改颜色。
注意:不需要Square(),可以用class + square()内部的函数(特别是渲染)代替,负责用给定上下文绘制rect。

    <!DOCTYPE html>
<meta charset="utf-8" />

<html>
  <head>
    <title>Cuadro cambia color // By Abraham Gonzalez</title>
  </head>

  <body id="myBody">
    <canvas id="canvas" width="400" height="400"></canvas>
  </body>

  <script>
    function btnRojoClic() {
      var canvas = document.getElementById('canvas');
      var ctx = canvas.getContext('2d');
      ctx.fillStyle = '#' + Math.floor(Math.random() * 16777215).toString(16);
    }
    // you cann also use a class instead, the main idea is to check if the click event position was on the square surface. 
    function square() {
      let position = 0;
      let tamano = 0;
      const increasePosition = () => {
        position;
      };
      const increaseSize = () => {
        tamano++;
      };
      const getPosition = () => {
        return position;
      };
      const getTamano = () => {
        return tamano;
      };
      const reset = () => {
        position = 0;
        tamno = 0;
      };
      const move = () => {
        increasePosition();
        increaseSize();
        if (position > 400) {
          reset();
        }
      };
      const render = (context) => {
        ctx.fillRect(position, 0, tamano, tamano);
      };
      return {
        move,
        render,
        getPosition,
        getTamano,
        reset
      };
    }
    /**
     * Get cursor position relativly to canvas 
     */
    const getCursorPosition = (canvas, event) => {
      const rect = canvas.getBoundingClientRect();
      const x = event.clientX - rect.left;
      const y = event.clientY - rect.top;
      return { x, y };
    };
    /**
     * Check if there is a collision (click position overlap square position) 
     * */
    const checkCollision = (canvas, ev, square) => {
      const { x, y } = getCursorPosition(canvas, ev);
      if (
        x >= square.getPosition() &&
        x <= square.getPosition() + square.getTamano() &&
        y >= square.getPosition() &&
        y <= square.getPosition() + square.getTamano()
      ) {
        canvas.getContext('2d').fillStyle =
          '#' + Math.floor(Math.random() * 16777215).toString(16);
      }
    };

    mySquare = square();

    var canvas = document.getElementById('canvas');
    var ctx = canvas.getContext('2d');
    canvas.addEventListener('click', (ev) =>
      checkCollision(canvas, ev, mySquare)
    );

    setInterval(function () {
      ctx.clearRect(0, 0, 400, 400);
      mySquare.move();
      mySquare.render();
    }, 30);
  </script>
</html>

Some things werent correct:

  • You never calling myBody()
  • myBody was a function and a var
  • rgb was undefined
<meta charset="utf-8" />

<html>
  <head>
    <title>Cuadro cambia color // By Abraham Gonzalez</title>
  </head>

  <body id="myBody">
    <canvas id="canvas" width="400" height="400"></canvas>
  </body>

  <script>
    function myBody() {
      var myBodyt = document.getElementById('myBody');
      myBodyt.addEventListener('click', btnRojoClic);
    }

    function btnRojoClic() {
      console.log('clickkeked');
      var canvas = document.getElementById('canvas');
      var ctx = canvas.getContext('2d');
      ctx.fillStyle = "#"+Math.floor(Math.random()*16777215).toString(16);
    }

    myBody();
    var canvas = document.getElementById('canvas');
    var ctx = canvas.getContext('2d');

    var posicion = 0;
    var tamano = 0;

    setInterval(function () {
      ctx.clearRect(0, 0, 400, 400);
      ctx.fillRect(posicion, 0, tamano, tamano);

      posicion++;
      tamano++;

      if (posicion > 400) {
        posicion = 0;
        tamano = 0;
      }
    }, 30);
  </script>
</html>

Edit only change color when the square is clicked. You cannot add an event listener directly on the rectangle (fillRect) but you can do it on the canvas. When there's a click, check if the event click position (x,y) is on the square (checkCollision ()) . If so change the color.
Note: the square() isn't necessary and can be replaced by a class + the functions (specially render) inside square() are responsible to draw the rect with the given context.

    <!DOCTYPE html>
<meta charset="utf-8" />

<html>
  <head>
    <title>Cuadro cambia color // By Abraham Gonzalez</title>
  </head>

  <body id="myBody">
    <canvas id="canvas" width="400" height="400"></canvas>
  </body>

  <script>
    function btnRojoClic() {
      var canvas = document.getElementById('canvas');
      var ctx = canvas.getContext('2d');
      ctx.fillStyle = '#' + Math.floor(Math.random() * 16777215).toString(16);
    }
    // you cann also use a class instead, the main idea is to check if the click event position was on the square surface. 
    function square() {
      let position = 0;
      let tamano = 0;
      const increasePosition = () => {
        position;
      };
      const increaseSize = () => {
        tamano++;
      };
      const getPosition = () => {
        return position;
      };
      const getTamano = () => {
        return tamano;
      };
      const reset = () => {
        position = 0;
        tamno = 0;
      };
      const move = () => {
        increasePosition();
        increaseSize();
        if (position > 400) {
          reset();
        }
      };
      const render = (context) => {
        ctx.fillRect(position, 0, tamano, tamano);
      };
      return {
        move,
        render,
        getPosition,
        getTamano,
        reset
      };
    }
    /**
     * Get cursor position relativly to canvas 
     */
    const getCursorPosition = (canvas, event) => {
      const rect = canvas.getBoundingClientRect();
      const x = event.clientX - rect.left;
      const y = event.clientY - rect.top;
      return { x, y };
    };
    /**
     * Check if there is a collision (click position overlap square position) 
     * */
    const checkCollision = (canvas, ev, square) => {
      const { x, y } = getCursorPosition(canvas, ev);
      if (
        x >= square.getPosition() &&
        x <= square.getPosition() + square.getTamano() &&
        y >= square.getPosition() &&
        y <= square.getPosition() + square.getTamano()
      ) {
        canvas.getContext('2d').fillStyle =
          '#' + Math.floor(Math.random() * 16777215).toString(16);
      }
    };

    mySquare = square();

    var canvas = document.getElementById('canvas');
    var ctx = canvas.getContext('2d');
    canvas.addEventListener('click', (ev) =>
      checkCollision(canvas, ev, mySquare)
    );

    setInterval(function () {
      ctx.clearRect(0, 0, 400, 400);
      mySquare.move();
      mySquare.render();
    }, 30);
  </script>
</html>

使用JavaScript任务:)

小镇女孩 2025-02-16 01:28:00

以下说明取自此页面

getElementsByClassName()方法返回文档中所有元素的集合,带有指定的类名称,作为Nodelist对象。

Nodelist对象表示节点的集合。节点可以是
通过索引号访问。索引从0。

开始

提示:您可以使用Nodelist对象的长度属性来确定具有指定类名称的元素数量,然后您可以循环浏览所有元素并提取所需的信息。

因此,作为参数getElementsByClassName将接受类名称。

如果这是您的html主体:

<div id="first" class="menuItem"></div>
<div id="second" class="menuItem"></div>
<div id="third" class="menuItem"></div>
<div id="footer"></div>

然后var menuitems = document.getElementsByClassName('menuitem')将返回3上&lt; div&gt; div&gt;的集合(而不是数组) S,因为它们匹配给定的班级名称。

然后,您可以在这种情况下迭代此节点(&lt; div&gt;在这种情况下)收集:

for (var menuItemIndex = 0 ; menuItemIndex < menuItems.length ; menuItemIndex ++) {
   var currentMenuItem = menuItems[menuItemIndex];
   // do stuff with currentMenuItem as a node.
}

请参阅此帖子有关元素和节点之间的差异的更多信息。

The following description is taken from this page:

The getElementsByClassName() method returns a collection of all elements in the document with the specified class name, as a NodeList object.

The NodeList object represents a collection of nodes. The nodes can be
accessed by index numbers. The index starts at 0.

Tip: You can use the length property of the NodeList object to determine the number of elements with a specified class name, then you can loop through all elements and extract the info you want.

So, as a parameter getElementsByClassName would accept a class name.

If this is your HTML body:

<div id="first" class="menuItem"></div>
<div id="second" class="menuItem"></div>
<div id="third" class="menuItem"></div>
<div id="footer"></div>

then var menuItems = document.getElementsByClassName('menuItem') would return a collection (not an array) of the 3 upper <div>s, as they match the given class name.

You can then iterate over this nodes (<div>s in this case) collection with:

for (var menuItemIndex = 0 ; menuItemIndex < menuItems.length ; menuItemIndex ++) {
   var currentMenuItem = menuItems[menuItemIndex];
   // do stuff with currentMenuItem as a node.
}

Please refer to this post for more on differences between elements and nodes.

queryselectorall()和getElementsby*()方法返回什么?

小镇女孩 2025-02-15 16:12:38

不,将路由器嵌套在另一个路由器中是一种不变的违规行为。我认为您的情况不是无效的嵌套情况,而是与 有关,其中 sweetalert正在渲染react jsx。从我回想起sweetAlert它的内容中,它会在ReactTree之外进行内容。

您当然可以渲染多个路由器,只要它们没有嵌套,但是问题是您已经单独处理路由/导航的单独路由上下文,并且在一个路由上下文中进行导航不会更新其他路由。

我怀疑您可以使用单个自定义历史参考并将其传递给所需的路由器,因此它们都在内部引用相同的历史记录上下文。

React-Router-dom@6导出a 为此目的,历史记录

示例:

import { createBrowserHistory } from "history";

const history = createBrowserHistory({ window });

export default history;

...

import * as React from "react";
import * as ReactDOM from "react-dom";
import { unstable_HistoryRouter as HistoryRouter } from "react-router-dom";
import history from "../path/to/history";

ReactDOM.render(
  <HistoryRouter history={history}>
    {/* The rest of your app goes here */}
  </HistoryRouter>,
  root
);

...

import { unstable_HistoryRouter as HistoryRouter } from "react-router-dom";
import history from "../path/to/history";

MySwal.fire({
  html: (
    <HistoryRouter history={history}>
      ...
    </HistoryRouter>
  ),
})

注意unstable_historyRouter

当前,此API以不稳定_前缀为前缀,因为您可以
无意间将两个版本的历史记录库添加到您的应用中,
您已添加到包装中的一个。
路由器内部使用。如果您的工具允许它,那是
建议不要将历史记录作为直接依赖性,而是依靠
在React-Router软件包的嵌套依赖性上。一旦我们有一个
检测错误匹配版本的机制,此API将删除其
不稳定的_前缀。

No, it is an invariant violation to nest a router within another router. I think your situation is not a case of invalid nesting, but more to do with where sweetalert is rendering the React JSX. From what I recall of sweetalert it renders content outside the ReactTree.

You can certainly render more than one router, so long as they are not nested, but then the issue is that you've separate routing contexts that each individually handle routing/navigation, and navigating within one routing context doesn't update the others.

I suspect you could use a single custom history reference and pass these to the routers you need, so they all reference the same history context internally.

react-router-dom@6 exports a HistoryRouter for this purpose.

Example:

import { createBrowserHistory } from "history";

const history = createBrowserHistory({ window });

export default history;

...

import * as React from "react";
import * as ReactDOM from "react-dom";
import { unstable_HistoryRouter as HistoryRouter } from "react-router-dom";
import history from "../path/to/history";

ReactDOM.render(
  <HistoryRouter history={history}>
    {/* The rest of your app goes here */}
  </HistoryRouter>,
  root
);

...

import { unstable_HistoryRouter as HistoryRouter } from "react-router-dom";
import history from "../path/to/history";

MySwal.fire({
  html: (
    <HistoryRouter history={history}>
      ...
    </HistoryRouter>
  ),
})

Note about unstable_HistoryRouter:

This API is currently prefixed as unstable_ because you may
unintentionally add two versions of the history library to your app,
the one you have added to your package.json and whatever version React
Router uses internally. If it is allowed by your tooling, it's
recommended to not add history as a direct dependency and instead rely
on the nested dependency from the react-router package. Once we have a
mechanism to detect mis-matched versions, this API will remove its
unstable_ prefix.

您可以在基于browserrouter的应用程序中实例化另一个“ browserrouter”吗?

小镇女孩 2025-02-15 11:42:47

尝试添加此内容,我不确定它是否适用于该页面,但是当我使用WebView时,我总是可以确保所有

webSettings.setLoadsImagesAutomatically(true);
webSettings.setDatabaseEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
    webSettings.setAllowFileAccessFromFileURLs(true);
    webSettings.setAllowUniversalAccessFromFileURLs(true);
}

try to add this, i'm not sure it's will work for that page but when i'm using webview i always enable all to be sure

webSettings.setLoadsImagesAutomatically(true);
webSettings.setDatabaseEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
    webSettings.setAllowFileAccessFromFileURLs(true);
    webSettings.setAllowUniversalAccessFromFileURLs(true);
}

WebView失败

小镇女孩 2025-02-14 11:18:03

为什么不使用JWT,它可以帮助您在指定的小时数中管理用户

Why not use JWT it can help you manage your users for the numbers of hours you specified

如何将cookie存储在颤音中并使用它来验证用户是否已登录

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文