小编iam*_*in.的帖子

vue cli 3 –在样式标签中使用背景图片

我想将组件之一中我的Assets文件夹中的svg图像用作背景图像。这是我的组件的一个示例:

<template>
  <div class="container"></div>
</template>

<script>
export default {
  name: 'component'
}
</script>

<style scoped lang="scss">
.container {
  height: 40px;
  width: 40px;
  background-image: url('@/assets/image.svg');
}
</style>
Run Code Online (Sandbox Code Playgroud)

但是图像没有显示。路径正确。我的错误在哪里?谢谢你的帮助。

css vue.js vue-cli

15
推荐指数
3
解决办法
9951
查看次数

在vue-cli 3中使用本地字体

我想将本地字体导入到我的vue-cli 3项目中。

.woff和.woff3文件位于src / assets / typo中,我将它们包括在src / scss / _typo.scss中: 在此处输入图片说明

我的_typo.scss看起来像这样:

@font-face {
  font-family: 'HKGrotesk';
  src:  url('@/assets/typo/HKGrotesk-Bold.woff2') format('woff2'),
        url('@/assets/typo/HKGrotesk-Bold.woff') format('woff');
  font-weight: bold;
  font-style: normal;
}

@font-face {
  font-family: 'HKGrotesk';
  src:  url('@/assets/typo/HKGrotesk-Medium.woff2') format('woff2'),
        url('@/assets/typo/HKGrotesk-Medium.woff') format('woff');
  font-weight: medium;
  font-style: normal;
}

@font-face {
  font-family: 'HKGrotesk';
  src:  url('@/assets/typo/HKGrotesk-Regular.woff2') format('woff2'),
        url('@/assets/typo/HKGrotesk-Regular.woff') format('woff');
  font-weight: normal;
  font-style: normal;
}
Run Code Online (Sandbox Code Playgroud)

这是我的vue.config,用于全局使用颜色和字体:

module.exports = {
  css: {
    loaderOptions: {
      sass: {
        data: `
          @import "@/scss/_colors.scss";
          @import "@/scss/_typo.scss";
        `
      }
    }
  }
};
Run Code Online (Sandbox Code Playgroud)

当我运行项目时,出现以下错误消息:

Failed to compile.

./src/App.vue?vue&type=style&index=0&lang=scss& …
Run Code Online (Sandbox Code Playgroud)

font-face vue.js vue-cli

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

p5.j​​s 中的噪声梯度

目标

插图和其他图形作品中常见的效果是两种颜色之间的渐变,它带有颗粒/噪点,从而获得非常特殊的效果。(特别是示例 3。)

我的研究已经展示了如何在 Illustrator 等软件中实现这种效果的许多解决方案,但我想使用 p5js 或 vanilla js 画布重新创建它。

在此输入图像描述

(来源:https://medium.com/@stefanhrlemann/how-to-create-noisy-risograph-style-gradients-and-textures-in-photoshop-in-3-ways-394d6012a93a

我的尝试

我已经尝试创建渐变并使用其顶部的像素阵列设置具有特定颜色的随机噪声。这只能部分达到预期的效果:

function draw() {
    setGradient(0, 0, width, height, color(0, 0, 0), color(255, 255 ,255));
    setNoise();
}

function setNoise() {
    loadPixels();
    for (let x = 0; x < width; x++ ) {
        for (let y = 0; y < height; y++ ) {
            if (random(1) > 0.9) {
                const index = (x + y * width) * 4;
                pixels[index] = 255;
                pixels[index + 1] = 255; …
Run Code Online (Sandbox Code Playgroud)

javascript gradient canvas p5.js

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

片段中使用.getActivity()后无法访问的语句

我想在片段中使用.getSystemService.当我使用.getActivity()来获取我的活动的上下文时,Android Studio在同一行中告诉我这是一个"无法访问的语句".

当我在使用"getActivity()"的行上方有一行时,它将显示顶部的这一行是无法访问的.

为什么以及如何解决这个问题?

public class NewNodeFragment extends Fragment {

//GPS SIGNAL
double pLat;
double pLong;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return inflater.inflate(R.layout.newnode_layout, container,false);

    //GPS SIGNAL
    LocationManager gpsmanager = (LocationManager)getActivity().getSystemService(Context.LOCATION_SERVICE);
    Location lastLocation = gpsmanager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

    if (lastLocation != null) {
        pLat = lastLocation.getLatitude();
        pLong = lastLocation.getLongitude();
    }

    LocationListener gpslistener = new mylocationListener();
    gpsmanager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, gpslistener);
}
Run Code Online (Sandbox Code Playgroud)

android fragment android-studio

4
推荐指数
2
解决办法
7123
查看次数

如何计算数组中的相同对象属性值

我有一个大型数组,具有以下结构:

let data = [
  {
    name: 'name1',
    values: {...},
  },
  {
    name: 'name1',
    values: {...},
  },
  {
    name: 'name2',
    values: {...},
  },
  {
    name: 'name1',
    values: {...},
  },
  {
    name: 'name3',
    values: {...},
  },
  ...
]
Run Code Online (Sandbox Code Playgroud)

我需要找到一种方法来计算每个名称在数据数组中作为名称值出现的频率.

因此,在此示例中,结果应如下所示:

let nameCounts = [
  {
     name: 'name1'
     count: 3
  },
  {
     name: 'name2'
     count: 1
  },
  {
     name: 'name3'
     count: 1
  }
]
Run Code Online (Sandbox Code Playgroud)

我正在努力为这个问题找到好办法.有任何想法吗?

javascript arrays

3
推荐指数
1
解决办法
102
查看次数

在元素的开头生成innerHTML

我想在现有元素的开头生成HTML代码.

这是现有的HTML元素:

<div id="container">
  <p>end of the element</p>
</div>
Run Code Online (Sandbox Code Playgroud)

使用我当前的解决方案,我将生成的元素添加到现有内容下面:

document.getElementById(container).innerHTML += "<p>start of the element</p>";
Run Code Online (Sandbox Code Playgroud)

如何使用innerHTML在元素的现有内容之上添加内容?

html javascript innerhtml

2
推荐指数
1
解决办法
242
查看次数

NodeJS - SyntaxError:意外的标记ILLEGAL

我在大学服务器上创建了一个ubuntu实例.我已经安装了NodeJS和NPM,可以通过FTP连接发送文件.

我将以下NodeJS webserver文件发送到我的intance并希望在实例ip-adress上运行它.

var http = require(“http“);
http.createServer(function(request, response) {
    response.writeHead(200, {‚content-type’: ‚text/plain‚});
    response.write(‘Hello World’);
    response.end;
}).listen(3000‚141.28.107.7);
console.log(“server is running“);
Run Code Online (Sandbox Code Playgroud)

当我运行此文件时

sudo nodejs server.js
Run Code Online (Sandbox Code Playgroud)

我收到以下错误消息:

sudo: unable to resolve host nodejs
/home/robin/files/webserver.js:1
(function (exports, require, module, __filename, __dirname) { var http = require(“http“);
                                                                                 ^

SyntaxError: Unexpected token ILLEGAL
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Function.Module.runMain (module.js:447:10)
    at startup (node.js:148:18)
    at node.js:405:3
Run Code Online (Sandbox Code Playgroud)

我在推理中的错误在哪里?谢谢!

ubuntu instance node.js npm

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