cari

Rumah  >  Soal Jawab  >  teks badan

Kaedah dan isu kitaran hayat dalam VueJS

Saya bergelut dengan kod ini dan atas sebab tertentu retrieveTutorials() ia tidak menghantar maklumat kepada baseDeDatosVias. Saya cuba menukar fungsi kepada kitaran hayat lain tetapi ia tidak berfungsi. Mungkin penyelesaiannya sangat mudah tetapi saya tidak menemuinya. Terima kasih terlebih dahulu atas bantuan anda! !

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

methods: {

  retrieveTutorials() {

    TutorialDataService.get(this.$auth.user.name)

      .then(response => {

        this.baseDeDatosVias = response.data;

        console.log(this.baseDeDatosVias);

      })

    .catch(e => {

      console.log(e);

    });

  },

 

 

  populateGrados() {

  this.retrieveTutorials();

  this.cantViasEncadadenasPorGrados= [];

  const keys = Object.keys(this.baseDeDatosVias);

  console.log(keys);

(Saya tahu saya juga perlu membetulkan semua "jika lain")

Kod lengkap adalah seperti berikut:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

<template>

  <div>

    <!--Stats cards-->

      <div class="row">

        <div class="col-lg-3 col-md-6 col-sm-6" v-for="stats in statsCards">

          <stats-card :type="stats.type"

                    :icon="stats.icon"

                    :small-title="stats.title"

                    :title="stats.value">

            <div class="stats" slot="footer">

              <i :class="stats.footerIcon"></i>

              {{stats.footerText}}

            </div>

          </stats-card>

        </div>

      </div> 

    <div class="row">

      <div class="col-md-6">

      <card>

        <template slot="header">

          <h4 class="card-title">Vias encadenadas por grado</h4>

          <p class="category">Por cantidad</p>

        </template>

         

        <bar-chart :labels="cantidadDeEncadenadas.labels"

                   :height="250"

                   :datasets="cantidadDeEncadenadas.datasets">

        </bar-chart>

        </card>

      </div>

    <div class="col-md-6">

      <card>

        <template slot="header">

          <h4 class="card-title">Progresion en el tiempo</h4>

          <p class="category">Proximamente</p>

        </template>

        <line-chart :labels="stockChart.labels"

                    :height="250"

                    :color="stockChart.color"

                    :extra-options="stockChart.options"

                    :datasets="stockChart.datasets">

        </line-chart>

      </card>

    </div>

      </div>

 

    <div class="row">

      <div class="col-lg-3 col-sm-6">

        <circle-chart-card :percentage="70"

                           chart-id="email-statistics-chart"

                           title="% de Vias Encadenadas"

                           description="Sobre el total de Realizadas"

                           color="#4acccd">

          <template slot="footer">

            <div class="legend">

              <i class="fa fa-circle text-info"></i> Encadenes

            </div>

            <hr>

           

          </template>

        </circle-chart-card>

      </div>

 

      <div class="col-lg-3 col-sm-6">

        <circle-chart-card :percentage="34"

                           chart-id="new-visitors-chart"

                           title="% de Vias a Vista"

                           description="Sobre el total de Encadenadas"

                           color="#fcc468">

          <template slot="footer">

            <div class="legend">

              <i class="fa fa-circle text-warning"></i> A Vista

            </div>

            <hr>

          </template>

        </circle-chart-card>

      </div> 

    </div>

 

  </div>

</template>

<script>

  import LineChart from 'src/components/UIComponents/Charts/LineChart'

  import CircleChartCard from 'src/components/UIComponents/Cards/CircleChartCard.vue'

  import ChartCard from 'src/components/UIComponents/Cards/ChartCard';

  import StatsCard from 'src/components/UIComponents/Cards/StatsCard';

  import {Badge} from 'src/components/UIComponents'

  import Loading from 'src/components/Dashboard/Layout/LoadingMainPanel.vue'

  import TaskList from './Widgets/TaskList'

  import BarChart from 'src/components/UIComponents/Charts/BarChart'

  import { Card } from 'src/components/UIComponents'

  import users from 'src/components/Dashboard/Views/Tables/users.js'

  import TutorialDataService from "src/services/TutorialDataService.js";

 

 

  const tooltipOptions = {

    tooltipFillColor: "rgba(0,0,0,0.5)",

    tooltipFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",

    tooltipFontSize: 14,

    tooltipFontStyle: "normal",

    tooltipFontColor: "#fff",

    tooltipTitleFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",

    tooltipTitleFontSize: 14,

    tooltipTitleFontStyle: "bold",

    tooltipTitleFontColor: "#fff",

    tooltipYPadding: 6,

    tooltipXPadding: 6,

    tooltipCaretSize: 8,

    tooltipCornerRadius: 6,

    tooltipXOffset: 10,

  };

 

  export default {

    components: {

      LineChart,

      Card,

      StatsCard,

      ChartCard,

      CircleChartCard,

      Badge,

      TaskList,

      BarChart,

      users

    },

    methods: {

      retrieveTutorials() {

        TutorialDataService.get(this.$auth.user.name)

          .then(response => {

            this.baseDeDatosVias = response.data;

            console.log(this.baseDeDatosVias);

          })

        .catch(e => {

          console.log(e);

        });

      },

 

 

      populateGrados() {

      this.retrieveTutorials();

      this.cantViasEncadadenasPorGrados= [];

      const keys = Object.keys(this.baseDeDatosVias);

      console.log(keys);

      keys.forEach((key, index) => {

        if ((`${this.baseDeDatosVias[key].encadenada}`) === "false"){

        } else if (`${this.baseDeDatosVias[key].grado}` === "5"){

          this.dataParaViasEncadenadas.quinto++;

        } else if(`${this.baseDeDatosVias[key].grado}`=== "5+"){

          this.dataParaViasEncadenadas.quintoMas++;

        } else if(`${this.baseDeDatosVias[key].grado}` === "6a"){

          this.dataParaViasEncadenadas.sextoA++;

        } else if(`${this.baseDeDatosVias[key].grado}` === "6a+"){

          this.dataParaViasEncadenadas.sextoAMas++;

        } else if(`${this.baseDeDatosVias[key].grado}` === "6b"){

          this.dataParaViasEncadenadas.sextoB++;

        } else if(`${this.baseDeDatosVias[key].grado}` === "6b+"){

          this.dataParaViasEncadenadas.sextoBMas++;

        } else if(`${this.baseDeDatosVias[key].grado}` === "6c"){

          this.dataParaViasEncadenadas.sextoC++;         

        } else if(`${this.baseDeDatosVias[key].grado}` === "6c+"){

          this.dataParaViasEncadenadas.sextoCMas++;

        } else if(`${this.baseDeDatosVias[key].grado}` === "7a"){

          this.dataParaViasEncadenadas.septimoA++;

        } else if(`${this.baseDeDatosVias[key].grado}` === "7a+"){

          this.dataParaViasEncadenadas.septimoAMas++;

        } else if(`${this.baseDeDatosVias[key].grado}` === "7b"){

          this.dataParaViasEncadenadas.septimoB++;

        } else if(`${this.baseDeDatosVias[key].grado}` === "7b+"){

          this.dataParaViasEncadenadas.septimoBMas++;         

        } else if(`${this.baseDeDatosVias[key].grado}` === "7c"){

          this.dataParaViasEncadenadas.septimoC++;

        } else if(`${this.baseDeDatosVias[key].grado}` == "7c+"){

          this.dataParaViasEncadenadas.septimoCMas++;         

            }

          });       

      let claves = Object.keys(this.dataParaViasEncadenadas);

      for (let i=0; i<claves.length; i++){

        let clave = claves[i];

        this.cantViasEncadadenasPorGrados.push(this.dataParaViasEncadenadas[clave]);

      }

      },

    },

    mounted(){

    this.populateGrados();

    this.cantidadDeEncadenadas= {

          labels: ["5", "5+", "6a" ,"6a+", "6b", "6b+", "6c", "6c+", "7a", "7a+", "7b", "7b+", "7c","7c+"],

          datasets: [

            {

              label: "Vias.",

              borderColor: '#fcc468',

              fill: true,

              backgroundColor: '#fcc468',

              hoverBorderColor: '#fcc468',

              borderWidth: 4,

              data: this.cantViasEncadadenasPorGrados,     

            },

          ]

      };

    },

 

    /**

     * Chart data used to render stats, charts. Should be replaced with server data

     */

    data () {

      return {

        tutorials: [],

      cantViasEncadadenasPorGrados: [],

      cantidadDeEncadenadas: null,

      baseDeDatosVias: [], // users funciona

      dataParaViasEncadenadas: {

          quinto: 0,

          quintoMas: 0,

          sextoA: 0,

          sextoAMas: 0,

          sextoB: 0,

          sextoBMas: 0,

          sextoC: 0,

          sextoCMas: 0,

          septimoA: 0,

          septimoAMas: 0,

          septimoB: 0,

          septimoBMas: 0,

          septimoC: 0,

          septimoCMas: 0,

        },

        stockChart: {

          labels: ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio"],

          datasets: [{

            label: "Cantidad de vias",

            borderColor: "#f17e5d",

            pointBackgroundColor: "#f17e5d",

            pointRadius: 3,

            pointHoverRadius: 3,

            lineTension: 0,

            fill: false,

            borderWidth: 3,

            data: [20, 25, 30, 35, 28, 33, 40]

          }],

          color: '#f17e5d',

          options: {

            showLine: false,

 

            tooltips: tooltipOptions,

            scales: {

              yAxes: [{

 

                ticks: {

                  fontColor: "#9f9f9f",

                  beginAtZero: false,

                  maxTicksLimit: 5,

                },

                gridLines: {

                  drawBorder: false,

                  borderDash: [8, 5],

                  zeroLineColor: "transparent",

                  color: '#9f9f9f'

                }

 

              }],

 

              xAxes: [{

                barPercentage: 1.6,

                gridLines: {

                  drawBorder: false,

                  borderDash: [8, 5],

                  color: '#9f9f9f',

                  zeroLineColor: "transparent"

                },

                ticks: {

                  padding: 20,

                  fontColor: "#9f9f9f"

                }

              }]

            }

          }

        },

 

        statsCards: [

          {

            type: 'warning',

            icon: 'nc-icon nc-globe',

            title: 'Total de Vias Encadenadas',

            value: '80',

            footerText: 'Actualizado ahora',

            footerIcon: 'nc-icon nc-refresh-69'

          },

          {

            type: 'success',

            icon: 'nc-icon nc-globe-2',

            title: 'Total de Vias Realizadas',

            value: '95',

            footerText: 'Actualizado ahora',

            footerIcon: 'nc-icon nc-refresh-69'

          },

          {

            type: 'danger',

            icon: 'nc-icon nc-vector',

            title: 'Vias realizadas el ultimo mes',

            value: '23',

            footerText: 'hace 30 dias',

            footerIcon: 'nc-icon nc-calendar-60'

          },

          {

            type: 'info',

            icon: 'nc-icon nc-favourite-28',

            title: 'Total Vias a Vista',

            value: '45',

            footerText: 'Actualizado ahora',

            footerIcon: 'nc-icon nc-refresh-69'

          }

        ],

        

       

        

         

 

      }

    }

  }

 

</script>

<style>

 

</style>

P粉504920992P粉504920992331 hari yang lalu434

membalas semua(1)saya akan balas

  • P粉463824410

    P粉4638244102024-03-30 11:33:28

    Nampak seperti isu tak segerak - cuba:

    1

    2

    3

    4

    async populateGrados() {

        await this.retrieveTutorials();

        // rest of the code

    }

    balas
    0
  • Batalbalas