小编Jou*_*usi的帖子

webpack 未将 [contenthash] 正确添加到我的 .js 文件中

我正在尝试设置文件的哈希值以反映内容,以便它们不会被缓存。

我发现的最好/最简单的方法是使用contenthast文件名,但是当我尝试它时,webpack 将其正确添加到我的.css和.map文件中,但不是我的.js files

                         static/js/vendor.[contenthash].js     651 kB       0  [emitted]  [big]  vendor
                           static/js/main.[contenthash].js     131 kB       1  [emitted]         main
                       static/js/manifest.[contenthash].js  869 bytes       2  [emitted]         manifest
      static/css/main.142c3dccf1d3eb2c02c84322b0cf2ef7.css     274 kB       1  [emitted]  [big]  main
  static/css/main.142c3dccf1d3eb2c02c84322b0cf2ef7.css.map     545 kB          [emitted]         
  static/js/vendor.651ccaf8218b875738b87d472058ef85.js.map    2.78 MB       0  [emitted]         vendor
    static/js/main.1d8c83094a24fff4097ced4e4b947bd5.js.map     471 kB       1  [emitted]         main
static/js/manifest.76f2ac98b5b1630c96bf2b7aeb5b3498.js.map    4.96 kB       2  [emitted]         manifest
Run Code Online (Sandbox Code Playgroud)

我的webpack.prod.conf.js样子:

/* eslint-disable */
'use strict'
const path = require('path')
const utils = require('./utils')
const webpack = require('webpack')
const …
Run Code Online (Sandbox Code Playgroud)

javascript webpack

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

Javascript getElementByClass().foreach函数不起作用

我试图用JS的类名获取HTML的每个元素,然后根据range对象中的值更改其高度和宽度onchange.

浏览器显示错误: document.getElementsByClassName(...).forEach is not a function

但我试图尽可能地构建它,但仍然没有......

这是我的第一个js代码的样子:

function updateInput(val) {
    document.getElementById('valueInput').innerHTML=val; /*This is just to show the value to the user*/
    document.getElementsByClassName('oneResult').forEach(functio??n changeWidth(element) { element.style.width = val + 'px'; } );
    document.getElementsByClassName('oneResult').forEach(functio??n changeWidth(element) { element.style.height = val + 'px'; } );
}
Run Code Online (Sandbox Code Playgroud)

然后我尝试了这个:

function updateInput(val) {
    document.getElementById('valueInput').innerHTML=val;
    function oneResultWH(element) {
        element.style.width = val + 'px';
        element.style.height = val + 'px';
    }
    document.getElementsByClassName('oneResult').forEach(oneResultWH);
}
Run Code Online (Sandbox Code Playgroud)

但还是没有运气..

这就是我的PHP的样子:

print '<div class="oneResult" style="background-image:url(Pictures/'.$img.'); height: 100px; width:100px; ">
<a …
Run Code Online (Sandbox Code Playgroud)

html javascript php foreach

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

Vue计算方法没有被调用

我有一个computed方法:

computed: {
  currentPosition () {
    if(this.get_local_storage_state()){
      return this.lastLocation
    }

    if (this.currentRestaurant) {
      return this.currentRestaurant.address.location
    } else if (this.searchPosition.lat && this.searchPosition.lon) {
      return this.searchPosition;
    } else {
      return null;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

哪个在我的电话中被调用<template>:

<GMap class="c-splitview__map" :markers="getMarkers" :position="currentPosition" :zoom="currentZoom" v-if="currentPosition" />
<div class="m-storefinder__placeholder" v-else>
  <h1 class="o-headline">{{$tc("storefinder.emptyDeeplink")}}</h1>
</div>
Run Code Online (Sandbox Code Playgroud)

并且出于某种原因,当它第一次被调用时,它的运行方式应该如何,但是当我再次尝试调用它时(重新渲染Vue组件)它不会被调用.

但!

当我注释掉第一个if()语句时,如下:

computed: {
  currentPosition () {
    // if(this.get_local_storage_state()){
    //  return this.lastLocation
    // }

    if (this.currentRestaurant) {
      return this.currentRestaurant.address.location
    } else if (this.searchPosition.lat && this.searchPosition.lon) {
      return …
Run Code Online (Sandbox Code Playgroud)

javascript state vue.js computed-properties vuejs2

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

尝试将child附加到具有相同类名的所有元素

我试图使用该appendChild()方法将document.createElement("div")元素添加到<div>具有相同类名的多个元素.

我试过这种方式:

const childElement = document.createElement("div");
childElement.className = "second";
const parentObject = document.getElementsByClassName("first");

[...parentObject].map(parent => parent.appendChild(childElement))
Run Code Online (Sandbox Code Playgroud)

哪个没用,所以我试过:

for(let i = 0; i < parentObject.length; i++){
  parentObject[i].appendChild(childElement);
}
Run Code Online (Sandbox Code Playgroud)

唯一可行的方法是,如果我自己编写html元素,然后将其添加到每个父元素的innerHTML中:

[...parentObject].map(parent => parent.innerHTML = "<div class='second'></div>")
Run Code Online (Sandbox Code Playgroud)

但是因为我正在生成所有不同类型的HTML元素标签,IMG, DIV, SPAN所以我需要调用createElement()方法的便利性.

有没有人有这方面的经验?

html javascript ecmascript-6

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

必须返回有效组件错误

我的代码:

import React, { Component } from 'react';
import ReactDOM from 'react-dom';

export default class App extends Component{
  render() {
    const numbers = {
      first : {
        name : "Dad",
        number : "1243342432",
        info : "Best dad ever!",
        birthDay : "4.2.1955"
      },
      second: {
        name : "Mom",
        number : "5435234523",
        info : "Best mom ever!",
        birthDay : "8.2.1967"
      },
      third: {
        name : "Martin",
        number : "5742253223",
        info : "Best friend Martin ever!",
        birthDay : ""
      }
    };  

    const FurtherInfo …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

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