請用splice
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title></title>
<style>
[v-cloak] {
display: none;
}
</style>
</head>
<body>
<div id="app" v-cloak>
<table border="1">
<tr v-for="item in list">
<td>{{item.name}}</td>
<td>{{item.age}}</td>
</tr>
</table>
<button @click="insert">在第二個位置插入一行</button>
</div>
<script src="https://cdn.bootcss.com/vue/2.4.4/vue.min.js"></script>
<script>
new Vue({
el: '#app',
data: {
list: [
{ name:'user1', age:10 },
{ name:'user2', age:20 },
{ name:'user3', age:30 }
]
},
methods: {
insert() {
this.list.splice(1,0, { name:'新插入的行', age: 100})
}
}
})
</script>
</body>
</html>可以在指令的宿主元素下加一個ng-container作為動態(tài)組件容器,ng-container會在渲染時消失。
指令可以做一些修改:
@Directive({
selector: '[appTxt]'
})
export class TxtCopyDirective {
@Input('appTxt') dyView:any
constructor(
private el: ElementRef,
private renderer2: Renderer2,
public viewContainerRef: ViewContainerRef,
private componentFactoryResolver: ComponentFactoryResolver
) {}
@HostListener('click', ['$event']) onclick(event: any) {
this.dyView.clear();
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(動態(tài)組件);
this.dyView.createComponent(componentFactory);
}
}
目標(biāo)元素:
<span [appTxt]="dyView">
click
<ng-container #dy></ng-container>
</span>
目標(biāo)元素所在組件獲取ng-container容器作為參數(shù)傳給指令:
@ViewChild('dy',{read:ViewContainerRef}) dyView:ViewContainerRef官網(wǎng)有豎向的屬性,vertical表示豎向的。但沒有配置index索引值順序(看源碼也可以發(fā)現(xiàn))。但可以DOM操作下。
// 路徑:element@1.x/packages/steps/src/step.vue (1.4.9版本)
<span class="el-step__icon">
<slot
v-if="currentStatus !== 'success' && currentStatus !== 'error'"
name="icon">
<i v-if="icon" :class="['el-icon-' + icon]"></i>
<div v-else>{{ index + 1 }}</div>
</slot>
<i
v-else
:class="['el-icon-' + (currentStatus === 'success' ? 'check' : 'close')]">
</i>
</span>
// HTML
<script src="http://unpkg.com/vue/dist/vue.js"></script>
<script src="http://unpkg.com/element-ui@1.4.9/lib/index.js"></script>
<div id="app">
<el-steps :space="100" direction="vertical" :active="1">
<el-step title="步驟 3"></el-step>
<el-step title="步驟 2"></el-step>
<el-step title="步驟 1"></el-step>
</el-steps>
</div>
// JS
new Vue({
mounted(){
[...document.querySelectorAll('.el-steps .el-step__icon div')].forEach((el, index, arr) => {
console.log(el, arr.length - index); // 3,2,1
el.innerHTML = arr.length - index;
});
},
}).$mount('#app')
// CSS
@import url("http://unpkg.com/element-ui@1.4.9/lib/theme-default/index.css");
手機A 操作得到狀態(tài)Sa post給云服務(wù)器S
手機B 操作得到狀態(tài)Sb post給云服務(wù)器S
手機A 心跳包get服務(wù)器S 獲得狀態(tài)Sb
手機B 心跳包get服務(wù)器S 獲得狀態(tài)Sa
以上是http層的對戰(zhàn)方式(缺點實時性差)
手機A,B均socket連接云服務(wù)器S,服務(wù)器S建立room server實時轉(zhuǎn)發(fā)雙方消息
(缺點服務(wù)器壓力山大)
1:封裝的時候你可以將定時器id作為返回值的一部分,然后通過clearInterval清除
2:封裝里面加上清除的操作的方法
devserver里加上
historyApiFallback: {
// Paths with dots should still use the history fallback.
// See https://github.com/facebookincubator/create-react-app/issues/387.
disableDotRule: true,
},1,更改devtool參數(shù),在index.js中
devtool: 'source-map',
這樣我們就能得到具體的錯誤信息.
2,如果我們還使用了ES6中的API,比如Promise,它將不會得到IE瀏覽器的支持,所以我們需要引用 'babel-polyfill'
webpack.base.conf.js
entry: {
normal: ['babel-polyfill', './src/main.js']
},
main.js
import 'babel-polyfill';
3,引用插件是否已經(jīng)得到正確的編譯,我所使用到的插件,比如element-ui,vis等沒有得到正確的編譯,更改 'webpack.base.conf.js'文件
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test'), resolve('/node_modules/element-ui/src')]
}
// 前提是你必須安裝對應(yīng)的工具依賴
{
test: /node_modules[\\\/]vis[\\\/].*\.js$/,
loader: 'babel-loader',
query: {
cacheDirectory: true,
presets: [ "babel-preset-es2015" ].map(require.resolve),
plugins: [
"transform-es3-property-literals", // #2452
"transform-es3-member-expression-literals", // #2566
"transform-runtime" // #2566
]
}
}
Node v8.11.3
npm v5.6.0
"dependencies": {
"axios": "^0.18.0",
"babel-preset-es2015": "^6.24.1",
"element-ui": "^2.4.5",
"js-cookie": "^2.2.0",
"lodash": "^4.17.10",
"md5": "^2.2.1",
"moment": "^2.22.2",
"vee-validate": "^2.1.0-beta.6",
"vue": "^2.5.2",
"vue-cookies": "^1.5.6",
"vue-iconfont": "^1.1.0",
"vue-router": "^3.0.1",
"vuex": "^3.0.1"
},
"devDependencies": {
"autoprefixer": "^7.1.2",
"babel-cli": "^6.26.0",
"babel-core": "^6.22.1",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-loader": "^7.1.1",
"babel-plugin-component": "^1.1.1",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-plugin-transform-vue-jsx": "^3.5.0",
"babel-plugin-transform-es3-member-expression-literals": "^6.22.0",
"babel-plugin-transform-es3-property-literals": "^6.22.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.3.2",
"babel-preset-stage-2": "^6.22.0",
"chalk": "^2.0.1",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.28.11",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^1.1.4",
"friendly-errors-webpack-plugin": "^1.6.1",
"html-webpack-plugin": "^2.30.1",
"less": "^3.7.0",
"less-loader": "^4.1.0",
"node-notifier": "^5.1.2",
"node-sass": "^4.9.2",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"ora": "^1.2.0",
"portfinder": "^1.0.13",
"postcss-import": "^11.0.0",
"postcss-loader": "^2.0.8",
"postcss-url": "^7.2.1",
"rimraf": "^2.6.0",
"sass-loader": "^7.0.3",
"semver": "^5.3.0",
"shelljs": "^0.7.6",
"style-loader": "^0.21.0",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.2",
"uglifyjs-webpack-plugin": "^1.1.1",
"url-loader": "^0.5.8",
"vis": "^4.21.0",
"vue-loader": "^13.3.0",
"vue-style-loader": "^3.1.2",
"vue-template-compiler": "^2.5.2",
"webpack": "^3.6.0",
"webpack-bundle-analyzer": "^2.9.0",
"webpack-dev-server": "^2.7.1",
"webpack-merge": "^4.1.0"
},
謝謝 Nine 的幫助
debugger的時候,看不到源碼?
瀏覽器有沒有安裝react dev-tool?
為了安全考慮,通過腳本沒辦法獲取的,不過可以通過控制臺區(qū)獲取
image 標(biāo)簽是你自己寫的組件還是原生標(biāo)簽???有這個原生標(biāo)簽嘛?
供參考
const s2 = new Set(arr2.map(x => x.id))
const new1 = arr1.filter(x => !s2.delete(x.id))
const new2 = arr2.filter(x => s2.has(x.id))你用了getFieldDecorator以后Input組件的修改數(shù)據(jù)會被Form托管,你的onChange會被Form的方法覆蓋,你看下antd的文檔
額onChange不會被覆蓋 是我想錯了 剛寫了個demo測了下 不會出現(xiàn)不能更新input值的情況 我看你的Input是個自己的組件 你的onChange方法是怎么實現(xiàn)的?有沒有獲取到Form通過props傳給你的更新后重新調(diào)用this.props.onChange?
找你們后端,如果是做前端分頁讓他返回所有數(shù)據(jù),也很可能是后端分頁而你們沒對清楚接口
response.data.data.list.forEach(function(item){
...
console.log(that.total);//打印了10次12 意思是list長度本來就是10
});
list.forEach里面push,如果你只是想格式化數(shù)組用map。更不要在forEach里重復(fù)的執(zhí)行無用的 that.total = ...和 that.tableData = ...,10次循環(huán)前面9次都是無用的賦值。你注釋打開的那幾個路由跟user組件也沒關(guān)系啊,雖然你名字起的是Userxxx。
全是獨立的路由,每次跳轉(zhuǎn)都被銷毀,watch來不及執(zhí)行。
補充,不是說/user/a就一定是/user的子路由,在定義router的時候必須有明確的children關(guān)系才是。況且你的代碼里連路徑的層級關(guān)系都沒有。
再補充。不會,你可以在router-view外加個keep-alive,然后這種情況下路由組件不會被銷毀,你能看到watch:"$route"是能執(zhí)行的。然后簡單看了下源代碼:
Vue.prototype.$destroy = function () {
// teardown watchers
if (vm._watcher) {
vm._watcher.teardown();
}
while (i--) {
vm._watchers[i].teardown();
}
}
Vue的$destory里有一步是.teardown(),此方法會將watcher的this.active = falseactive屬性置為false,當(dāng)watcher執(zhí)行時發(fā)現(xiàn)active為false會直接跳過。
在watcher的隊列里,watch對應(yīng)的watcher是在destory對應(yīng)的watcher之后的,所以destory后,當(dāng)前銷毀組件的所有watcher就會被全部跳過不再執(zhí)行。至于為什么是這個順序,沒看。
watch和watcher是兩個東西,watch是監(jiān)聽api,watcher是所有相關(guān)操作的一個對象,包括watch的回調(diào),計算屬性,render等操作。
你這個應(yīng)該是 第二次輸出 是因為你刷新頁面 它請求沒有完畢你就輸出了result把
"我自己也用react+antd和express寫了一個能實現(xiàn)登陸,文章發(fā)表文章回復(fù),歸檔"
上面這點就能找到工作了,我一個朋友,連react express碰都沒碰過,整天就知道切圖,還不是工作的好好的
我猜你是在vuex里面使用的axios對吧?
那你在vuex的里面有沒有正確引入axios呢?
get請求的話只能拼接url
detailList[0].costPointsNum=0&detailList[0].exchangeNum=0&detailList[0].schemeId=0
其實就是做一個緩存處理嘛。
可以創(chuàng)建一個數(shù)組,數(shù)據(jù)結(jié)構(gòu)可以是這樣的:
const cacheData = [
{ tab: "", data: {} },
{ tab: "", data: {} },
.....
]
每當(dāng)你成功請求一個標(biāo)簽后,可以將對于的數(shù)據(jù)緩存里面,然后再次請求此標(biāo)簽的時候,去數(shù)組里面找,如果找到則使用緩存的數(shù)據(jù),如果沒找到,則請求API。
當(dāng)然這種情況適用于, 標(biāo)簽對應(yīng)的數(shù)據(jù)不變的情況下,如果數(shù)據(jù)可能隨時改變,那你就要時時請求API.
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
達(dá)內(nèi)教育集團成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
北大課工場是北京大學(xué)校辦產(chǎn)業(yè)為響應(yīng)國家深化產(chǎn)教融合/校企合作的政策,積極推進“中國制造2025”,實現(xiàn)中華民族偉大復(fù)興的升級產(chǎn)業(yè)鏈。利用北京大學(xué)優(yōu)質(zhì)教育資源及背
博為峰,中國職業(yè)人才培訓(xùn)領(lǐng)域的先行者
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團項目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗,技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點難點突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。