小编Den*_*soi的帖子

Vue 3 中的 ref 与反应式?

看一些人的 Vue 3 预览教程的一些例子。 [目前是测试版]

我找到了两个例子:

反应式

<template>
  <button @click="increment">
    Count is: {{ state.count }}, double is: {{ state.double }}
  </button>
</template>

<script>
import { reactive, computed } from 'vue'

export default {
  setup() {
    const state = reactive({
      count: 0,
      double: computed(() => state.count * 2)
    })

    function increment() {
      state.count++
    }

    return {
      state,
      increment
    }
  }
}
</script>
Run Code Online (Sandbox Code Playgroud)

参考

<template>
  <div>
    <h2 ref="titleRef">{{ formattedMoney }}</h2>
    <input v-model="delta" type="number">
    <button @click="add">Add</button>
  </div>
</template>

<script>
import { ref, computed, …
Run Code Online (Sandbox Code Playgroud)

vuejs3 vue-composition-api

58
推荐指数
3
解决办法
2万
查看次数

Angular 6 many无法解决错误(crypto,fs,http,https,net,path,stream,tls,zlib)

我正在构建一个Angular 6应用程序,但每次我想为localhost服务时,我都会收到以下错误:

ERROR in ./node_modules/aws-sign2/index.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\aws-sign2'
ERROR in ./node_modules/aws4/aws4.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\aws4'
ERROR in ./node_modules/ecc-jsbn/index.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\ecc-jsbn'
ERROR in ./node_modules/http-signature/lib/signer.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\http-signature\lib'
ERROR in ./node_modules/http-signature/lib/verify.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\http-signature\lib'
ERROR in ./node_modules/oauth-sign/index.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\oauth-sign'
ERROR in ./node_modules/request/lib/oauth.js
Module not found: …
Run Code Online (Sandbox Code Playgroud)

node.js npm webpack angular angular6

42
推荐指数
6
解决办法
2万
查看次数

JS:将长字符串拆分为具有字符限制的字符串,同时避免拆分单词

我正在尝试将大块文本分成多个字符串,每个字符串为148个字符,同时避免切断单词.

我现在有这个,这是分裂的话:

var length = shortData.new.length;

if (length < 160){

  outputString[0] = shortData.new;
  document.write(outputString[0]);

}


if (length > 160 && length < 308){

  outputString[0] = shortData.new.substring(0,148);
  outputString[1] = shortData.new.substring(148,length);    

  document.write(outputString[0]+"(txt4more..)");   
  document.write(outputString[1]);      

}


if (length > 308 && length < 468){


  outputString[0] = shortData.new.substring(0,148);
  outputString[1] = shortData.new.substring(148,308);   
  outputString[2] = shortData.new.substring(308,length);    

  document.write(outputString[0]+"(txt4more..)");   
  document.write(outputString[1]+"(txt4more..)");   
  document.write(outputString[2]);      

}


if (length > 468 && length < 641){


  outputString[0] = shortData.new.substring(0,148);
  outputString[1] = shortData.new.substring(148,308);   
  outputString[2] = shortData.new.substring(308,468);   
  outputString[3] = shortData.new.substring(468,length);    

  document.write(outputString[0]+"(txt4more..)");   
  document.write(outputString[1]+"(txt4more..)");   
  document.write(outputString[2]+"(txt4more..)");   
  document.write(outputString[3]);      

}
Run Code Online (Sandbox Code Playgroud)

javascript regex sms

15
推荐指数
1
解决办法
5447
查看次数

使用Angular JS ng-src的后备(默认)图像

我正在尝试使用从模态返回的数据设置图像源.这是在ng-repeat循环中:

<div id="divNetworkGrid">
    <div id="{{network.id}}" ng-repeat="network in networks">
        <span>
            <table>
                <tr>
                    <td class="imgContainer">
                        <img ng-src="{{ ('assets/img/networkicons/'+ network.actual + '.png') || 
                                         'assets/img/networkicons/default.png' }}"/>
                    </td>
                </tr>
            </table>
        </span>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

很明显,当network.actual模型属性返回null时,我想填充default.png.但是我的代码没有拿起默认图像,尽管第一张图像在可用时会很好.

我确定这是一些语法问题,但无法弄清楚是什么问题.

fallback image src angularjs

14
推荐指数
6
解决办法
3万
查看次数

Dockerfile:有没有办法从 .env 文件中读取变量

我想读取文件中PORT定义的 Dockerfile 中的变量.env。有没有办法做到这一点?

这是我的 Dockerfile:

FROM node:11-alpine

RUN mkdir -p /usr/src/app

WORKDIR /usr/src/app

ENV PORT=3000

COPY . .

RUN npm install

EXPOSE 3000

CMD ["npm", "run", "start"]
Run Code Online (Sandbox Code Playgroud)

environment-variables docker dockerfile docker-compose

10
推荐指数
1
解决办法
6620
查看次数

首先ajax调用非常慢,后续调用很快 - 为什么?

我正在使用一个简单的jQuery AJAX函数,它在第一次调用时运行速度非常慢(10-15秒),然后每次在第一次调用后运行正常<1 - 2秒.我无法弄清楚为什么会发生这种情况,但需要尽可能加快速度.这是功能:

function getNewItemAlt(apiUrl, callType, apiKey, dataType, returnValue, appendToWrapper) {
// ajax call to the api
  return $.ajax({
    type: callType,
    url: apiUrl,
    data: apiKey,
    dataType: dataType,
    success: function(result) {

        appendToWrapper.closest('.game_play_area').find('.game_loader').remove();

        // this is the thing that we want (probably either
        // an image url or an actual value)
        var desiredReturn = deepValue(result, returnValue);

        var specialClass = '';
        console.log(typeof desiredReturn)
        if (typeof desiredReturn === 'number') {
            specialClass = 'number'
        }

        // if it's a URL then it's an image …
Run Code Online (Sandbox Code Playgroud)

javascript ajax jquery

8
推荐指数
1
解决办法
1405
查看次数

如何解决 Gatsby 中的 &lt;StoreStateProvider&gt; 错误?

我克隆了一个 gatsby 应用程序,并在运行开发服务器时:

$ gatsby develop
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

The above error occurred in the <StoreStateProvider> component:
    in StoreStateProvider
    in App
Run Code Online (Sandbox Code Playgroud)
React will try to recreate this component tree from scratch using the error boundary you provided, App.


 ERROR

Warning: App: Error boundaries should implement getDerivedStateFromError(). In that method, return a state update to display an error message or fallback UI.


 ERROR

UNHANDLED REJECTION Invalid hook call. Hooks can only be called inside of the body of a function component. This could …
Run Code Online (Sandbox Code Playgroud)

gatsby

8
推荐指数
1
解决办法
930
查看次数

如何在Chrome/Canary Dev Tools中显示代码覆盖率功能

正在阅读使用chrome dev工具新的代码覆盖功能,并且无法尝试启用此功能.

我知道Canary可以在不需要取消标记的情况下实现这一点,但我不确定从哪里可以在Chrome Devtools中找到此功能.

google-chrome google-chrome-devtools

7
推荐指数
2
解决办法
3560
查看次数

打印功能仅在第二次单击后有效

我有这个功能来打印DIV.
每当页面加载并点击我的"打印"链接时,显示DIV没有CSS打印.
如果我关闭Chrome的打印可视化页面并再次单击"打印"链接,则DIV会应用CSS.

有什么想法吗?

使用Javascript

function printDiv(divId) {

  var printDivCSSpre =
'<link href="/static/assets/vendor/sb-admin-2-1.0.7/bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">' +
'<link href="/static/assets/vendor/sb-admin-2-1.0.7/dist/css/sb-admin-2.css" rel="stylesheet">' +
'<div style="width:1000px; padding-right:20px;">';

  var printDivCSSpost = '</div>';

  $('body').append('<iframe id="print_frame" name="print_frame" width="0" height="0" frameborder="0" src="about:blank"></iframe>');

    $("link").clone().appendTo($("#print_frame").contents().find("head"));
window.frames["print_frame"].document.body.innerHTML =
    printDivCSSpre + document.getElementById(divId).innerHTML + printDivCSSpost;
  window.frames["print_frame"].window.focus();
  var windowInstance = window.frames["print_frame"].window;
  windowInstance.print();
}
Run Code Online (Sandbox Code Playgroud)

HTML

<a id="print" href="#">
    <i class="fa fa-print"></i> Print
</a>
<script>
    $('#print').click(function () {
        printDiv('report')
    })
</script>

<div id="report" class="report">
    <p># Generated Table#</p>
</div>
Run Code Online (Sandbox Code Playgroud)

首先点击:

http://imgur.com/a/Go81Y

关闭打印预览页面并再次单击打印

http://imgur.com/a/SCxJF

javascript

6
推荐指数
1
解决办法
1373
查看次数

Sklearn模型(Python)与NodeJS(Express):如何将两者连接?

我有一个使用NodeJS-Express的Web服务器,并且在同一台机器上腌制(倾倒)了一个Scikit-Learn(机器学习)模型。

我需要的是通过向服务器发送/接收数据来演示该模型。我想在Web服务器启动时加载模型,并保持“监听”数据输入。接收数据时,执行预测并将其发送回。

我对Python比较陌生。从我所看到的,我可以使用“子进程”来执行它。我还看到了一些从Node运行Python脚本的模块。

问题是我想一次加载模型并且只要服务器开启就让它运行。由于尺寸过大,我不想每次都继续加载模型。最佳的执行方式是什么?

这个想法是在AWS机器上运行所有内容。

先感谢您。

python child-process node.js scikit-learn

5
推荐指数
1
解决办法
840
查看次数